Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions lib/matplotex/element/rad_legend.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
defmodule Matplotex.Element.RadLegend do
@moduledoc false
alias Matplotex.Utils.Algebra
alias Matplotex.Element.Label
alias Matplotex.Element
alias Matplotex.Element.Rect
Expand All @@ -10,6 +11,9 @@ defmodule Matplotex.Element.RadLegend do
@stroke "rgba(0,0,0,0)"
@legend_size 20 / 96
@label_type "legend.label"
@default_opacity 1.0

@legend_padding 5/96
defstruct [
:type,
:x,
Expand All @@ -20,6 +24,8 @@ defmodule Matplotex.Element.RadLegend do
height: @legend_size,
label_margin: @legend_size,
stroke: @stroke,
stroke_opacity: @default_opacity,
fill_opacity: @default_opacity,
stroke_width: @stroke_width
]

Expand All @@ -41,12 +47,13 @@ defmodule Matplotex.Element.RadLegend do
} = legend,
legend_font
) do
{label_x, label_y} = Algebra.transform_given_point(x, y, width + @legend_padding, height/2)
%{
legend
| label:
%Label{
x: x + width,
y: y + height / 2,
x: label_x,
y: label_y,
text: text,
type: @label_type
}
Expand Down
5 changes: 3 additions & 2 deletions lib/matplotex/figure/radial/pie.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ defmodule Matplotex.Figure.Radial.Pie do
use Radial

@full_circle 2 * :math.pi()
@legend_padding 5/96
chord(
center: %TwoD{},
lead: %TwoD{},
Expand Down Expand Up @@ -68,7 +69,7 @@ defmodule Matplotex.Figure.Radial.Pie do
when fwidth > 0 and fheight > 0 do
%Region{x: legx, y: legy} = Algebra.flip_y_coordinate(region_legend)
total_size = Enum.sum(sizes)
legend_rect_side = height / length(sizes) / 2
legend_rect_side = height / length(sizes) / 4
center = Algebra.flip_y_coordinate(center)

slices =
Expand Down Expand Up @@ -143,7 +144,7 @@ defmodule Matplotex.Figure.Radial.Pie do
}

{x_legend, y_legend} =
Algebra.transform_given_point(0, legend_unit_height, x_legend, y_legend)
Algebra.transform_given_point(0, legend_unit_height + @legend_padding, x_legend, y_legend)

legend =
%RadLegend{
Expand Down
8 changes: 4 additions & 4 deletions lib/matplotex/helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -258,11 +258,11 @@ defmodule Matplotex.Helpers do

def pie() do
# Percentages for each slice
sizes = [25, 35, 20, 20]
sizes = [25, 35, 20, 20, 10]
# Labels for each slice
labels = ["A", "B", "C", "D"]
labels = ["A", "B", "C", "D", "E"]
# Colors for the slices
colors = ["lightblue", "lightgreen", "orange", "pink"]
colors = ["#33BBEE", "#EE7733", "#EE3377", "#0077BB","#919D41"]

sizes
|> Matplotex.pie(colors: colors, labels: labels)
Expand Down Expand Up @@ -311,7 +311,7 @@ defmodule Matplotex.Helpers do

def hist() do
values = Nx.Random.key(12) |> Nx.Random.normal(0, 1, shape: {1000}) |> elem(0) |> Nx.to_list()
bins = 30
bins = 100

Matplotex.hist(values, bins,
x_label: "Value",
Expand Down
Loading