| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -201,6 +201,31 @@ def _forward_ilshift(self, other): | |||
| 201 | 201 | 'numpy %s or later is required; you have %s' % ( | |
| 202 | 202 | __version__numpy__, numpy.__version__)) | |
| 203 | 203 | ||
| 204 | + import functools | ||
| 205 | + def _interactive(func): | ||
| 206 | + """ | ||
| 207 | + Decorator for Figure and Axes methods that will be wrapped in pyplot. | ||
| 208 | + | ||
| 209 | + Methods so decorated no longer need a call to `draw_if_interactive` | ||
| 210 | + in their pyplot wrappers, and are interactive when invoked as | ||
| 211 | + methods with a gui backend in interactive mode. | ||
| 212 | + | ||
| 213 | + Figure and Axes must define the methods `check_interactive`, | ||
| 214 | + `draw_if_interactive`, and `clear_interactive` used in this | ||
| 215 | + decorator. | ||
| 216 | + """ | ||
| 217 | + @functools.wraps(func) | ||
| 218 | + def inner(self, *args, **kw): | ||
| 219 | + outer = self.check_interactive() | ||
| 220 | + drawn = True # default in "finally" clause is to clear. | ||
| 221 | + try: | ||
| 222 | + ret = func(self, *args, **kw) | ||
| 223 | + drawn = self.draw_if_interactive(outer) | ||
| 224 | + finally: | ||
| 225 | + self.clear_interactive(drawn) | ||
| 226 | + return ret | ||
| 227 | + return inner | ||
| 228 | + | ||
| 204 | 229 | ||
| 205 | 230 | def _is_writable_dir(p): | |
| 206 | 231 | """ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -38,6 +38,7 @@ | |||
| 38 | 38 | from matplotlib.container import BarContainer, ErrorbarContainer, StemContainer | |
| 39 | 39 | from matplotlib.axes._base import _AxesBase | |
| 40 | 40 | from matplotlib.axes._base import _process_plot_format | |
| 41 | + from matplotlib import _interactive # decorator | ||
| 41 | 42 | ||
| 42 | 43 | rcParams = matplotlib.rcParams | |
| 43 | 44 | ||
@@ -1235,6 +1236,7 @@ def eventplot(self, positions, orientation='horizontal', lineoffsets=1, | |||
| 1235 | 1236 | return colls | |
| 1236 | 1237 | ||
| 1237 | 1238 | #### Basic plotting | |
| 1239 | + @_interactive | ||
| 1238 | 1240 | @docstring.dedent_interpd | |
| 1239 | 1241 | def plot(self, *args, **kwargs): | |
| 1240 | 1242 | """ | |
@@ -2530,6 +2532,7 @@ def pie(self, x, explode=None, labels=None, colors=None, | |||
| 2530 | 2532 | else: | |
| 2531 | 2533 | return slices, texts, autotexts | |
| 2532 | 2534 | ||
| 2535 | + @_interactive | ||
| 2533 | 2536 | @docstring.dedent_interpd | |
| 2534 | 2537 | def errorbar(self, x, y, yerr=None, xerr=None, | |
| 2535 | 2538 | fmt='', ecolor=None, elinewidth=None, capsize=3, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -30,9 +30,8 @@ | |||
| 30 | 30 | import matplotlib.text as mtext | |
| 31 | 31 | import matplotlib.image as mimage | |
| 32 | 32 | from matplotlib.artist import allow_rasterization | |
| 33 | - | ||
| 34 | - | ||
| 35 | 33 | from matplotlib.cbook import iterable | |
| 34 | + from matplotlib import is_interactive | ||
| 36 | 35 | ||
| 37 | 36 | rcParams = matplotlib.rcParams | |
| 38 | 37 | ||
@@ -442,6 +441,7 @@ def __init__(self, fig, rect, | |||
| 442 | 441 | self.set_cursor_props((1, 'k')) # set the cursor properties for axes | |
| 443 | 442 | ||
| 444 | 443 | self._cachedRenderer = None | |
| 444 | + self._in_outer_method = False | ||
| 445 | 445 | self.set_navigate(True) | |
| 446 | 446 | self.set_navigate_mode(None) | |
| 447 | 447 | ||
@@ -461,6 +461,40 @@ def __init__(self, fig, rect, | |||
| 461 | 461 | self._ycid = self.yaxis.callbacks.connect('units finalize', | |
| 462 | 462 | self.relim) | |
| 463 | 463 | ||
| 464 | + | ||
| 465 | + def draw_if_interactive(self, outer=False): | ||
| 466 | + print("entering draw_if_interactive in axes/_base, outer = ", outer) | ||
| 467 | + # Not sure whether this should be public or private... | ||
| 468 | + if not outer or not is_interactive(): | ||
| 469 | + return False | ||
| 470 | + # Leave out the following check for now; it probably | ||
| 471 | + # has to be modified so that it does not require importing | ||
| 472 | + # all the available interactive backends just to make | ||
| 473 | + # the list of canvases. Instead, the check could be based | ||
| 474 | + # on the str() or (repr) of self.canvas. | ||
| 475 | + #if not isinstance(self.canvas, interactive_canvases): | ||
| 476 | + # return | ||
| 477 | + self.figure.canvas.draw() | ||
| 478 | + print("drawing complete in axes/_base") | ||
| 479 | + return True | ||
| 480 | + | ||
| 481 | + def check_interactive(self): | ||
| 482 | + """ | ||
| 483 | + Return True upon entering an outer method, and set the | ||
| 484 | + flag; return False if already in an outer method. | ||
| 485 | + """ | ||
| 486 | + if not self._in_outer_method: | ||
| 487 | + self._in_outer_method = True | ||
| 488 | + print("checking: toggled _in_outer_method to True") | ||
| 489 | + return True | ||
| 490 | + print("checking: already _in_outer_method; returning False") | ||
| 491 | + return False | ||
| 492 | + | ||
| 493 | + def clear_interactive(self, drawn): | ||
| 494 | + if drawn: | ||
| 495 | + self._in_outer_method = False | ||
| 496 | + | ||
| 497 | + | ||
| 464 | 498 | def __setstate__(self, state): | |
| 465 | 499 | self.__dict__ = state | |
| 466 | 500 | # put the _remove_method back on all artists contained within the axes | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -24,7 +24,9 @@ | |||
| 24 | 24 | from matplotlib import rcParams | |
| 25 | 25 | from matplotlib import docstring | |
| 26 | 26 | from matplotlib import __version__ as _mpl_version | |
| 27 | + | ||
| 27 | 28 | from matplotlib import is_interactive | |
| 29 | + from matplotlib import _interactive # decorator | ||
| 28 | 30 | ||
| 29 | 31 | import matplotlib.artist as martist | |
| 30 | 32 | from matplotlib.artist import Artist, allow_rasterization | |
@@ -234,20 +236,6 @@ def _update_this(self, s, val): | |||
| 234 | 236 | ||
| 235 | 237 | setattr(self, s, val) | |
| 236 | 238 | ||
| 237 | - import functools | ||
| 238 | - def _interactive(func): | ||
| 239 | - @functools.wraps(func) | ||
| 240 | - def inner(self, *args, **kw): | ||
| 241 | - outer = self.check_interactive() | ||
| 242 | - drawn = True # default in "finally" clause is to clear. | ||
| 243 | - try: | ||
| 244 | - ret = func(self, *args, **kw) | ||
| 245 | - drawn = self.draw_if_interactive(outer) | ||
| 246 | - finally: | ||
| 247 | - self.clear_interactive(drawn) | ||
| 248 | - return ret | ||
| 249 | - return inner | ||
| 250 | - | ||
| 251 | 239 | class Figure(Artist): | |
| 252 | 240 | ||
| 253 | 241 | """ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2761,7 +2761,7 @@ def errorbar(x, y, yerr=None, xerr=None, fmt='', ecolor=None, elinewidth=None, | |||
| 2761 | 2761 | barsabove=barsabove, lolims=lolims, uplims=uplims, | |
| 2762 | 2762 | xlolims=xlolims, xuplims=xuplims, | |
| 2763 | 2763 | errorevery=errorevery, capthick=capthick, **kwargs) | |
| 2764 | - draw_if_interactive() | ||
| 2764 | + #draw_if_interactive() | ||
| 2765 | 2765 | finally: | |
| 2766 | 2766 | ax.hold(washold) | |
| 2767 | 2767 | ||
@@ -3095,7 +3095,7 @@ def plot(*args, **kwargs): | |||
| 3095 | 3095 | ax.hold(hold) | |
| 3096 | 3096 | try: | |
| 3097 | 3097 | ret = ax.plot(*args, **kwargs) | |
| 3098 | - draw_if_interactive() | ||
| 3098 | + #draw_if_interactive() | ||
| 3099 | 3099 | finally: | |
| 3100 | 3100 | ax.hold(washold) | |
| 3101 | 3101 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments