Skip to content

Commit 29564f9

Browse files
committed
Fix _sizes lookup
1 parent 1aaca33 commit 29564f9

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/tikzplotlib/_legend.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,24 @@ def draw_legend(data, obj):
6161
if fill_xcolor != "white": # white is default
6262
legend_style.append(f"fill={fill_xcolor}")
6363

64-
6564
mark_options = []
66-
handles = obj.legendHandles if hasattr(obj, "legendHandles") else obj.legend_handles if hasattr(obj, "legend_handles") else None
65+
handles = (
66+
obj.legendHandles
67+
if hasattr(obj, "legendHandles")
68+
else obj.legend_handles if hasattr(obj, "legend_handles") else None
69+
)
6770
if handles and any(hasattr(handle, "_sizes") for handle in handles):
68-
all_sizes = set(sz for handle in handles for sz in handle._sizes if hasattr(handle, "_sizes"))
71+
handles_with_sizes = [handle for handle in handles if hasattr(handle, "_sizes")]
72+
all_sizes = set(sz for handle in handles_with_sizes for sz in handle._sizes)
6973
if len(all_sizes) > 1:
70-
warnings.warn(f"Varying marker sizes in the legend: {all_sizes}. Ignoring all of them.")
74+
warnings.warn(
75+
f"Varying marker sizes in the legend: {all_sizes}. Ignoring all of them."
76+
)
7177
elif all_sizes:
7278
mark_size = all_sizes.pop()
7379
ff = data["float format"]
7480
# setting half size because pgfplots counts the radius/half-width, and sqrt the area
75-
pgf_size = 0.5 * mark_size ** 0.5
81+
pgf_size = 0.5 * mark_size**0.5
7682
mark_options.append(f"mark size={pgf_size:{ff}}")
7783

7884
if mark_options:

0 commit comments

Comments
 (0)