Skip to content

Commit cad53a8

Browse files
committed
Merge and fix errors
2 parents fc62ef4 + 358fb4b commit cad53a8

File tree

2 files changed

+27
-22
lines changed

2 files changed

+27
-22
lines changed

docs/environment.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ dependencies:
1616
- sphinx
1717
- ipython
1818
- ipykernel
19-
- jupyter
2019
- pip:
2120
- lxml
2221
- pyyaml

proplot/wrappers.py

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,10 @@ class _CenteredLegend(martist.Artist):
106106
def __str__(self):
107107
return 'CenteredLegend'
108108

109-
110-
def __init__(self, pairs, loc=None, **kwargs):
109+
def __init__(
110+
self, pairs, loc=None, title=None, markerfirst=None,
111+
frameon=None, framealpha=None, fancybox=None, shadow=None,
112+
**kwargs):
111113
"""
112114
Parameters
113115
----------
@@ -134,6 +136,9 @@ def __init__(self, pairs, loc=None, **kwargs):
134136
# Determine space we want sub-legend to occupy as fraction of height
135137
# NOTE: Empirical testing shows spacing fudge factor necessary to
136138
# exactly replicate the spacing of standard aligned legends.
139+
legs = []
140+
ymin, ymax = None, None
141+
width, height = self.figure.get_size_inches()
137142
fontsize = kwargs.get('fontsize', None) or rc['legend.fontsize']
138143
spacing = kwargs.get('labelspacing', None) or rc['legend.labelspacing']
139144
interval = 1 / len(pairs) # split up axes
@@ -166,46 +171,49 @@ def __init__(self, pairs, loc=None, **kwargs):
166171
legs.append(leg)
167172

168173
# Store legend and add frame
169-
self.leg = legs
174+
self.legs = legs
170175
if not frameon:
171176
return
172177
if len(legs) == 1:
173178
legs[0].set_frame_on(True) # easy!
174179
return
175180

176181
# Draw legend frame encompassing centered rows
177-
facecolor = _notNone(facecolor, rcParams['legend.facecolor'])
182+
edgecolor = _notNone(
183+
kwargs.get('edgecolor', None), rc['legend.edgecolor'])
184+
facecolor = _notNone(
185+
kwargs.get('facecolor', None), rc['legend.facecolor'])
178186
if facecolor == 'inherit':
179-
facecolor = rcParams['axes.facecolor']
180-
self.legendPatch = FancyBboxPatch(
187+
facecolor = rc['axes.facecolor']
188+
patch = mpatches.FancyBboxPatch(
181189
xy=(0.0, 0.0), width=1.0, height=1.0,
182190
facecolor=facecolor,
183191
edgecolor=edgecolor,
184192
mutation_scale=fontsize,
185193
transform=self.transAxes,
186-
snap=True
187-
)
194+
snap=True)
195+
self.legendPatch = patch
188196

189197
# Box style
190198
if fancybox is None:
191-
fancybox = rcParams['legend.fancybox']
199+
fancybox = rc['legend.fancybox']
192200
if fancybox:
193-
self.legendPatch.set_boxstyle('round', pad=0, rounding_size=0.2)
201+
patch.set_boxstyle('round', pad=0, rounding_size=0.2)
194202
else:
195-
self.legendPatch.set_boxstyle('square', pad=0)
196-
self._set_artist_props(self.legendPatch)
203+
patch.set_boxstyle('square', pad=0)
204+
self._set_artist_props(patch)
197205
self._drawFrame = frameon
198206

199207
# Initialize with null renderer
200-
self._init_legend_box(handles, labels, markerfirst)
208+
self._init_legend_box(*pairs, markerfirst)
201209

202210
# If shadow is activated use framealpha if not
203211
# explicitly passed. See Issue 8943
204212
if framealpha is None:
205213
if shadow:
206214
self.get_frame().set_alpha(1)
207215
else:
208-
self.get_frame().set_alpha(rcParams['legend.framealpha'])
216+
self.get_frame().set_alpha(rc['legend.framealpha'])
209217
else:
210218
self.get_frame().set_alpha(framealpha)
211219

@@ -214,21 +222,19 @@ def __init__(self, pairs, loc=None, **kwargs):
214222
else:
215223
patch.set_boxstyle('square', pad=0)
216224
patch.set_clip_on(False)
217-
patch.update(outline)
225+
# patch.update(outline)
218226
self.add_artist(patch)
219227
# Add shadow
220228
# TODO: This does not work, figure out
221229
if kwargs.get('shadow', rc['legend.shadow']):
222230
shadow = mpatches.Shadow(patch, 20, -20)
223231
self.add_artist(shadow)
224-
# Add patch to list
225-
legs = (patch, *legs)
226-
227232

228-
def draw(renderer):
233+
def draw(self, renderer):
229234
"""
230235
Draw the legend and the patch.
231236
"""
237+
legs = self.legs
232238
for leg in legs:
233239
leg.draw(renderer)
234240

@@ -250,7 +256,7 @@ def draw(renderer):
250256

251257
if self._drawFrame:
252258
if self.shadow:
253-
shadow = Shadow(self.legendPatch, 2, -2)
259+
shadow = mpatches.Shadow(self.legendPatch, 2, -2)
254260
shadow.draw(renderer)
255261

256262
self.legendPatch.draw(renderer)
@@ -2502,7 +2508,7 @@ def legend_wrapper(
25022508
ncol = _notNone(ncol, 3)
25032509
if order == 'C':
25042510
fpairs = []
2505-
split = [pairs[i * ncol:(i + 1) * ncol] # split into rows
2511+
split = [pairs[i * ncol:(i + 1) * ncol] # split into rows
25062512
for i in range(len(pairs) // ncol + 1)]
25072513
# Max possible row count, and columns in final row
25082514
nrowsmax, nfinalrow = len(split), len(split[-1])

0 commit comments

Comments
 (0)