| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -88,3 +88,8 @@ Setting :rc:`text.latex.preamble` or :rc:`pdf.preamble` to non-strings | |||
| 88 | 88 | These rcParams should be set to string values. Support for None (meaning the | |
| 89 | 89 | empty string) and lists of strings (implicitly joined with newlines) is | |
| 90 | 90 | deprecated. | |
| 91 | + | ||
| 92 | + ``Quiver.ax`` | ||
| 93 | + ~~~~~~~~~~~~~ | ||
| 94 | + This property is deprecated in favor of ``Quiver.axes``, for consistency with | ||
| 95 | + other artists. | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -259,7 +259,7 @@ def __init__(self, Q, X, Y, U, label, | |||
| 259 | 259 | self.color = color | |
| 260 | 260 | self.label = label | |
| 261 | 261 | self._labelsep_inches = labelsep | |
| 262 | - self.labelsep = (self._labelsep_inches * Q.ax.figure.dpi) | ||
| 262 | + self.labelsep = (self._labelsep_inches * Q.axes.figure.dpi) | ||
| 263 | 263 | ||
| 264 | 264 | # try to prevent closure over the real self | |
| 265 | 265 | weak_self = weakref.ref(self) | |
@@ -272,8 +272,8 @@ def on_dpi_change(fig): | |||
| 272 | 272 | # the start of draw. | |
| 273 | 273 | self_weakref._initialized = False | |
| 274 | 274 | ||
| 275 | - self._cid = Q.ax.figure.callbacks.connect('dpi_changed', | ||
| 276 | - on_dpi_change) | ||
| 275 | + self._cid = Q.axes.figure.callbacks.connect( | ||
| 276 | + 'dpi_changed', on_dpi_change) | ||
| 277 | 277 | ||
| 278 | 278 | self.labelpos = labelpos | |
| 279 | 279 | self.labelcolor = labelcolor | |
@@ -293,13 +293,10 @@ def on_dpi_change(fig): | |||
| 293 | 293 | self.zorder = Q.zorder + 0.1 | |
| 294 | 294 | ||
| 295 | 295 | def remove(self): | |
| 296 | - """ | ||
| 297 | - Overload the remove method | ||
| 298 | - """ | ||
| 299 | - self.Q.ax.figure.callbacks.disconnect(self._cid) | ||
| 296 | + # docstring inherited | ||
| 297 | + self.Q.axes.figure.callbacks.disconnect(self._cid) | ||
| 300 | 298 | self._cid = None | |
| 301 | - # pass the remove call up the stack | ||
| 302 | - martist.Artist.remove(self) | ||
| 299 | + super().remove() # pass the remove call up the stack | ||
| 303 | 300 | ||
| 304 | 301 | def _init(self): | |
| 305 | 302 | if True: # not self._initialized: | |
@@ -358,16 +355,12 @@ def draw(self, renderer): | |||
| 358 | 355 | self.stale = False | |
| 359 | 356 | ||
| 360 | 357 | def _set_transform(self): | |
| 361 | - if self.coord == 'data': | ||
| 362 | - self.set_transform(self.Q.ax.transData) | ||
| 363 | - elif self.coord == 'axes': | ||
| 364 | - self.set_transform(self.Q.ax.transAxes) | ||
| 365 | - elif self.coord == 'figure': | ||
| 366 | - self.set_transform(self.Q.ax.figure.transFigure) | ||
| 367 | - elif self.coord == 'inches': | ||
| 368 | - self.set_transform(self.Q.ax.figure.dpi_scale_trans) | ||
| 369 | - else: | ||
| 370 | - raise ValueError('unrecognized coordinates') | ||
| 358 | + self.set_transform(cbook._check_getitem({ | ||
| 359 | + "data": self.Q.axes.transData, | ||
| 360 | + "axes": self.Q.axes.transAxes, | ||
| 361 | + "figure": self.Q.axes.figure.transFigure, | ||
| 362 | + "inches": self.Q.axes.figure.dpi_scale_trans, | ||
| 363 | + }, coordinates=self.coord)) | ||
| 371 | 364 | ||
| 372 | 365 | def set_figure(self, fig): | |
| 373 | 366 | martist.Artist.set_figure(self, fig) | |
@@ -480,7 +473,7 @@ def __init__(self, ax, *args, | |||
| 480 | 473 | by the following pyplot interface documentation: | |
| 481 | 474 | %s | |
| 482 | 475 | """ | |
| 483 | - self.ax = ax | ||
| 476 | + self._axes = ax # The attr actually set by the Artist.axes property. | ||
| 484 | 477 | X, Y, U, V, C = _parse_args(*args, caller_name='quiver()') | |
| 485 | 478 | self.X = X | |
| 486 | 479 | self.Y = Y | |
@@ -513,8 +506,7 @@ def __init__(self, ax, *args, | |||
| 513 | 506 | self.set_UVC(U, V, C) | |
| 514 | 507 | self._initialized = False | |
| 515 | 508 | ||
| 516 | - # try to prevent closure over the real self | ||
| 517 | - weak_self = weakref.ref(self) | ||
| 509 | + weak_self = weakref.ref(self) # Prevent closure over the real self. | ||
| 518 | 510 | ||
| 519 | 511 | def on_dpi_change(fig): | |
| 520 | 512 | self_weakref = weak_self() | |
@@ -525,18 +517,17 @@ def on_dpi_change(fig): | |||
| 525 | 517 | # the start of draw. | |
| 526 | 518 | self_weakref._initialized = False | |
| 527 | 519 | ||
| 528 | - self._cid = self.ax.figure.callbacks.connect('dpi_changed', | ||
| 529 | - on_dpi_change) | ||
| 520 | + self._cid = ax.figure.callbacks.connect('dpi_changed', on_dpi_change) | ||
| 521 | + | ||
| 522 | + @cbook.deprecated("3.3", alternative="axes") | ||
| 523 | + def ax(self): | ||
| 524 | + return self.axes | ||
| 530 | 525 | ||
| 531 | 526 | def remove(self): | |
| 532 | - """ | ||
| 533 | - Overload the remove method | ||
| 534 | - """ | ||
| 535 | - # disconnect the call back | ||
| 536 | - self.ax.figure.callbacks.disconnect(self._cid) | ||
| 527 | + # docstring inherited | ||
| 528 | + self.axes.figure.callbacks.disconnect(self._cid) | ||
| 537 | 529 | self._cid = None | |
| 538 | - # pass the remove call up the stack | ||
| 539 | - mcollections.PolyCollection.remove(self) | ||
| 530 | + super().remove() # pass the remove call up the stack | ||
| 540 | 531 | ||
| 541 | 532 | def _init(self): | |
| 542 | 533 | """ | |
@@ -547,8 +538,7 @@ def _init(self): | |||
| 547 | 538 | # available to have this work on an as-needed basis at present. | |
| 548 | 539 | if True: # not self._initialized: | |
| 549 | 540 | trans = self._set_transform() | |
| 550 | - ax = self.ax | ||
| 551 | - self.span = trans.inverted().transform_bbox(ax.bbox).width | ||
| 541 | + self.span = trans.inverted().transform_bbox(self.axes.bbox).width | ||
| 552 | 542 | if self.width is None: | |
| 553 | 543 | sn = np.clip(math.sqrt(self.N), 8, 25) | |
| 554 | 544 | self.width = 0.06 * self.span / sn | |
@@ -609,31 +599,30 @@ def _dots_per_unit(self, units): | |||
| 609 | 599 | """ | |
| 610 | 600 | Return a scale factor for converting from units to pixels | |
| 611 | 601 | """ | |
| 612 | - ax = self.ax | ||
| 613 | 602 | if units in ('x', 'y', 'xy'): | |
| 614 | 603 | if units == 'x': | |
| 615 | - dx0 = ax.viewLim.width | ||
| 616 | - dx1 = ax.bbox.width | ||
| 604 | + dx0 = self.axes.viewLim.width | ||
| 605 | + dx1 = self.axes.bbox.width | ||
| 617 | 606 | elif units == 'y': | |
| 618 | - dx0 = ax.viewLim.height | ||
| 619 | - dx1 = ax.bbox.height | ||
| 607 | + dx0 = self.axes.viewLim.height | ||
| 608 | + dx1 = self.axes.bbox.height | ||
| 620 | 609 | else: # 'xy' is assumed | |
| 621 | - dxx0 = ax.viewLim.width | ||
| 622 | - dxx1 = ax.bbox.width | ||
| 623 | - dyy0 = ax.viewLim.height | ||
| 624 | - dyy1 = ax.bbox.height | ||
| 610 | + dxx0 = self.axes.viewLim.width | ||
| 611 | + dxx1 = self.axes.bbox.width | ||
| 612 | + dyy0 = self.axes.viewLim.height | ||
| 613 | + dyy1 = self.axes.bbox.height | ||
| 625 | 614 | dx1 = np.hypot(dxx1, dyy1) | |
| 626 | 615 | dx0 = np.hypot(dxx0, dyy0) | |
| 627 | 616 | dx = dx1 / dx0 | |
| 628 | 617 | else: | |
| 629 | 618 | if units == 'width': | |
| 630 | - dx = ax.bbox.width | ||
| 619 | + dx = self.axes.bbox.width | ||
| 631 | 620 | elif units == 'height': | |
| 632 | - dx = ax.bbox.height | ||
| 621 | + dx = self.axes.bbox.height | ||
| 633 | 622 | elif units == 'dots': | |
| 634 | 623 | dx = 1.0 | |
| 635 | 624 | elif units == 'inches': | |
| 636 | - dx = ax.figure.dpi | ||
| 625 | + dx = self.axes.figure.dpi | ||
| 637 | 626 | else: | |
| 638 | 627 | raise ValueError('unrecognized units') | |
| 639 | 628 | return dx | |
@@ -650,9 +639,9 @@ def _set_transform(self): | |||
| 650 | 639 | return trans | |
| 651 | 640 | ||
| 652 | 641 | def _angles_lengths(self, U, V, eps=1): | |
| 653 | - xy = self.ax.transData.transform(self.XY) | ||
| 642 | + xy = self.axes.transData.transform(self.XY) | ||
| 654 | 643 | uv = np.column_stack((U, V)) | |
| 655 | - xyp = self.ax.transData.transform(self.XY + eps * uv) | ||
| 644 | + xyp = self.axes.transData.transform(self.XY + eps * uv) | ||
| 656 | 645 | dxy = xyp - xy | |
| 657 | 646 | angles = np.arctan2(dxy[:, 1], dxy[:, 0]) | |
| 658 | 647 | lengths = np.hypot(*dxy.T) / eps | |
@@ -670,7 +659,7 @@ def _make_verts(self, U, V, angles): | |||
| 670 | 659 | # Calculate eps based on the extents of the plot | |
| 671 | 660 | # so that we don't end up with roundoff error from | |
| 672 | 661 | # adding a small number to a large. | |
| 673 | - eps = np.abs(self.ax.dataLim.extents).max() * 0.001 | ||
| 662 | + eps = np.abs(self.axes.dataLim.extents).max() * 0.001 | ||
| 674 | 663 | angles, lengths = self._angles_lengths(U, V, eps=eps) | |
| 675 | 664 | if str_angles and self.scale_units == 'xy': | |
| 676 | 665 | a = lengths | |
@@ -806,7 +795,6 @@ def _h_arrows(self, length): | |||
| 806 | 795 | : / \ \ \ | |
| 807 | 796 | : ------------------------------ | |
| 808 | 797 | ||
| 809 | - | ||
| 810 | 798 | The largest increment is given by a triangle (or "flag"). After those | |
| 811 | 799 | come full lines (barbs). The smallest increment is a half line. There | |
| 812 | 800 | is only, of course, ever at most 1 half line. If the magnitude is | |
@@ -818,8 +806,6 @@ def _h_arrows(self, length): | |||
| 818 | 806 | ||
| 819 | 807 | See also https://en.wikipedia.org/wiki/Wind_barb. | |
| 820 | 808 | ||
| 821 | - | ||
| 822 | - | ||
| 823 | 809 | Parameters | |
| 824 | 810 | ---------- | |
| 825 | 811 | X, Y : 1D or 2D array-like, optional | |
| Back | FazBrowse Home | New Git URL |
0 commit comments