Skip to content

Commit 9b0dac1

Browse files
Merge pull request #49 from BigThinkcode/multidatabar
Multidatabar
2 parents a69f6de + 6436040 commit 9b0dac1

File tree

4 files changed

+13
-7
lines changed

4 files changed

+13
-7
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ The package can be installed by adding <font color="darkblue"> **Matplotex**</fo
3939
```elixir
4040
def deps do
4141
[
42-
{:matplotex, "~> 0.4.6" }
42+
{:matplotex, "~> 0.4.71" }
4343
]
4444
```
4545

lib/matplotex.ex

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,6 @@ defmodule Matplotex do
176176
Generates a bar chart using the provided values and bar widths.
177177
178178
## Parameters
179-
180179
- `values` (list of numbers): A list of numerical values representing the heights of the bars in the chart.
181180
- `width` (floatiung point number): The width of each bar in inches.
182181
- `opts` (keyword list): It will support all opts mentioned above, some bar specific options are there those are
@@ -226,6 +225,11 @@ defmodule Matplotex do
226225
## Parameters
227226
228227
- `figure` (%Figure{}): The figure to which the new dataset will be added.
228+
- `pos` (floating point number) : In multi-dataset plots, the bar position is determined by a numerical offset.
229+
- Positive values shift the bar to the right of the tick.
230+
- Negative values shift the bar to the left of the tick.
231+
- Zero keeps the bar centered on the tick.
232+
This allows precise alignment and spacing between multiple datasets in a bar chart
229233
- `values` (list): A list of numerical values representing the heights of the bars in the new dataset.
230234
- `width` (float): The width of the bars in the dataset.
231235
- `opts` (keyword list, optional): A set of options for customizing the appearance of the new dataset, such as color and label.
@@ -240,10 +244,12 @@ defmodule Matplotex do
240244
categories = ["apple", "banana", "fig", "avocado"]
241245
values1 = [22, 33, 28, 34]
242246
values2 = [53, 63, 59, 60]
247+
values3 = [53, 63, 59, 60]
243248
width = 0.22
244249
245-
Matplotex.bar(width, values1, width, label: "Dataset1", color: "#255199")
246-
|> M.bar(width, values2, width, label: "Dataset2", color: "#D3D3D3")
250+
Matplotex.bar(-width, values1, width, label: "Dataset1", color: "#255199")
251+
|> M.bar(0, values2, width, label: "Dataset2", color: "#D3D3D3")
252+
|> M.bar(width, values2, width, label: "Dataset3", color: "green")
247253
"""
248254
def bar(%Figure{} = figure, pos, values, width, opts) do
249255
figure

lib/matplotex/figure/areal/bar_chart.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,11 @@ defmodule Matplotex.Figure.Areal.BarChart do
168168
@xmin_value |> Nx.linspace(nof_x, n: nof_x) |> Nx.to_list()
169169
end
170170

171-
defp bar_position(x, pos_factor) when pos_factor < 0 do
171+
defp bar_position(x, pos_factor) do
172172
x + pos_factor
173173
end
174174

175-
defp bar_position(x, _pos_factor), do: x
175+
176176

177177
defp list_of_ticks(data, step) do
178178
1..length(data)

mix.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ defmodule Matplotex.MixProject do
55
[
66
app: :matplotex,
77
organization: :bigthinkcode,
8-
version: "0.4.7",
8+
version: "0.4.71",
99
elixir: "~> 1.17",
1010
start_permanent: Mix.env() == :prod,
1111
elixirc_paths: elixirc_paths(Mix.env()),

0 commit comments

Comments
 (0)