|
17 | 17 | plot, *fontsize* is the fontsize in pixels, and *handlebox* is a
|
18 | 18 | OffsetBox instance. Within the call, you should create relevant
|
19 | 19 | artists (using relevant properties from the *legend* and/or
|
20 |
| -*orig_handle*) and add them into the handlebox. The artists needs to |
| 20 | +*orig_handle*) and add them into the handlebox. The artists need to |
21 | 21 | be scaled according to the fontsize (note that the size is in pixel,
|
22 | 22 | i.e., this is dpi-scaled value).
|
23 | 23 |
|
@@ -46,7 +46,7 @@ def update_from_first_child(tgt, src):
|
46 | 46 |
|
47 | 47 | class HandlerBase:
|
48 | 48 | """
|
49 |
| - A Base class for default legend handlers. |
| 49 | + A base class for default legend handlers. |
50 | 50 |
|
51 | 51 | The derived classes are meant to override *create_artists* method, which
|
52 | 52 | has a following signature.::
|
@@ -319,7 +319,7 @@ def patch_func(legend=legend, orig_handle=orig_handle,
|
319 | 319 | xdescent=xdescent, ydescent=ydescent,
|
320 | 320 | width=width, height=height, fontsize=fontsize)
|
321 | 321 |
|
322 |
| - Subsequently the created artist will have its ``update_prop`` |
| 322 | + Subsequently, the created artist will have its ``update_prop`` |
323 | 323 | method called and the appropriate transform will be applied.
|
324 | 324 |
|
325 | 325 | **kwargs
|
@@ -353,37 +353,33 @@ class HandlerStepPatch(HandlerBase):
|
353 | 353 | Handler for `~.matplotlib.patches.StepPatch` instances.
|
354 | 354 | """
|
355 | 355 |
|
356 |
| - def _create_patch(self, legend, orig_handle, |
357 |
| - xdescent, ydescent, width, height, fontsize): |
358 |
| - p = Rectangle(xy=(-xdescent, -ydescent), |
359 |
| - color=orig_handle.get_facecolor(), |
360 |
| - width=width, height=height) |
361 |
| - return p |
362 |
| - |
363 |
| - # Unfilled StepPatch should show as a line |
364 |
| - def _create_line(self, legend, orig_handle, |
365 |
| - xdescent, ydescent, width, height, fontsize): |
| 356 | + @staticmethod |
| 357 | + def _create_patch(orig_handle, xdescent, ydescent, width, height): |
| 358 | + return Rectangle(xy=(-xdescent, -ydescent), width=width, |
| 359 | + height=height, color=orig_handle.get_facecolor()) |
366 | 360 |
|
367 |
| - # Overwrite manually because patch and line properties don't mix |
| 361 | + @staticmethod |
| 362 | + def _create_line(orig_handle, width, height): |
| 363 | + # Unfilled StepPatch should show as a line |
368 | 364 | legline = Line2D([0, width], [height/2, height/2],
|
369 | 365 | color=orig_handle.get_edgecolor(),
|
370 | 366 | linestyle=orig_handle.get_linestyle(),
|
371 | 367 | linewidth=orig_handle.get_linewidth(),
|
372 | 368 | )
|
373 | 369 |
|
| 370 | + # Overwrite manually because patch and line properties don't mix |
374 | 371 | legline.set_drawstyle('default')
|
375 | 372 | legline.set_marker("")
|
376 | 373 | return legline
|
377 | 374 |
|
378 | 375 | def create_artists(self, legend, orig_handle,
|
379 | 376 | xdescent, ydescent, width, height, fontsize, trans):
|
380 | 377 | if orig_handle.get_fill() or (orig_handle.get_hatch() is not None):
|
381 |
| - p = self._create_patch(legend, orig_handle, |
382 |
| - xdescent, ydescent, width, height, fontsize) |
| 378 | + p = self._create_patch(orig_handle, xdescent, ydescent, width, |
| 379 | + height) |
383 | 380 | self.update_prop(p, orig_handle, legend)
|
384 | 381 | else:
|
385 |
| - p = self._create_line(legend, orig_handle, |
386 |
| - xdescent, ydescent, width, height, fontsize) |
| 382 | + p = self._create_line(orig_handle, width, height) |
387 | 383 | p.set_transform(trans)
|
388 | 384 | return [p]
|
389 | 385 |
|
|
0 commit comments