File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -63,6 +63,29 @@ def draw_legend(data, obj):
6363 if fill_xcolor != "white" : # white is default
6464 legend_style .append (f"fill={ fill_xcolor } " )
6565
66+ mark_options = []
67+ handles = (
68+ obj .legendHandles
69+ if hasattr (obj , "legendHandles" )
70+ else obj .legend_handles if hasattr (obj , "legend_handles" ) else None
71+ )
72+ if handles and any (hasattr (handle , "_sizes" ) for handle in handles ):
73+ handles_with_sizes = [handle for handle in handles if hasattr (handle , "_sizes" )]
74+ all_sizes = set (sz for handle in handles_with_sizes for sz in handle ._sizes )
75+ if len (all_sizes ) > 1 :
76+ warnings .warn (
77+ f"Varying marker sizes in the legend: { all_sizes } . Ignoring all of them."
78+ )
79+ elif all_sizes :
80+ mark_size = all_sizes .pop ()
81+ ff = data ["float format" ]
82+ # setting half size because pgfplots counts the radius/half-width, and sqrt the area
83+ pgf_size = 0.5 * mark_size ** 0.5
84+ mark_options .append (f"mark size={ pgf_size :{ff }} " )
85+
86+ if mark_options :
87+ legend_style .append (f"mark options={{{ ', ' .join (mark_options )} }}" )
88+
6689 # Get the horizontal alignment
6790 try :
6891 alignment = children_alignment [0 ]
You can’t perform that action at this time.
0 commit comments