|
31 | 31 | from matplotlib.font_manager import FontProperties |
32 | 32 | from matplotlib.lines import Line2D |
33 | 33 | from matplotlib.patches import Patch, Rectangle, Shadow, FancyBboxPatch |
34 | | -from matplotlib.collections import LineCollection, RegularPolyCollection |
| 34 | +from matplotlib.collections import LineCollection, RegularPolyCollection, \ |
| 35 | + CircleCollection |
35 | 36 | from matplotlib.transforms import Bbox, BboxBase, TransformedBbox, BboxTransformTo |
36 | 37 |
|
37 | 38 | from matplotlib.offsetbox import HPacker, VPacker, TextArea, DrawingArea |
@@ -439,7 +440,8 @@ def _init_legend_box(self, handles, labels): |
439 | 440 | # manually set their transform to the self.get_transform(). |
440 | 441 |
|
441 | 442 | for handle in handles: |
442 | | - if isinstance(handle, RegularPolyCollection): |
| 443 | + if isinstance(handle, RegularPolyCollection) or \ |
| 444 | + isinstance(handle, CircleCollection): |
443 | 445 | npoints = self.scatterpoints |
444 | 446 | else: |
445 | 447 | npoints = self.numpoints |
@@ -531,6 +533,31 @@ def _init_legend_box(self, handles, labels): |
531 | 533 | p.set_clip_path(None) |
532 | 534 | handle_list.append(p) |
533 | 535 |
|
| 536 | + elif isinstance(handle, CircleCollection): |
| 537 | + |
| 538 | + ydata = height*self._scatteryoffsets |
| 539 | + |
| 540 | + size_max, size_min = max(handle.get_sizes()),\ |
| 541 | + min(handle.get_sizes()) |
| 542 | + # we may need to scale these sizes by "markerscale" |
| 543 | + # attribute. But other handle types does not seem |
| 544 | + # to care about this attribute and it is currently ignored. |
| 545 | + if self.scatterpoints < 4: |
| 546 | + sizes = [.5*(size_max+size_min), size_max, |
| 547 | + size_min] |
| 548 | + else: |
| 549 | + sizes = (size_max-size_min)*np.linspace(0,1,self.scatterpoints)+size_min |
| 550 | + |
| 551 | + p = type(handle)(sizes, |
| 552 | + offsets=zip(xdata_marker,ydata), |
| 553 | + transOffset=self.get_transform(), |
| 554 | + ) |
| 555 | + |
| 556 | + p.update_from(handle) |
| 557 | + p.set_figure(self.figure) |
| 558 | + p.set_clip_box(None) |
| 559 | + p.set_clip_path(None) |
| 560 | + handle_list.append(p) |
534 | 561 | else: |
535 | 562 | handle_list.append(None) |
536 | 563 |
|
|
0 commit comments