diff --git a/boilerplate.py b/boilerplate.py index 1572158c30d1..fd643343496e 100644 --- a/boilerplate.py +++ b/boilerplate.py @@ -169,7 +169,7 @@ def boilerplate_gen(): #'spy' : 'sci(%(ret)s)', ### may return image or Line2D 'quiver' : 'sci(%(ret)s)', 'specgram' : 'sci(%(ret)s[-1])', - 'streamplot' : 'sci(%(ret)s)', + 'streamplot' : 'sci(%(ret)s.lines)', 'tricontour' : 'if %(ret)s._A is not None: sci(%(ret)s)', 'tricontourf': 'if %(ret)s._A is not None: sci(%(ret)s)', 'tripcolor' : 'sci(%(ret)s)', diff --git a/lib/matplotlib/artist.py b/lib/matplotlib/artist.py index 48a7b1f26361..fefad44f349b 100644 --- a/lib/matplotlib/artist.py +++ b/lib/matplotlib/artist.py @@ -228,10 +228,11 @@ def set_transform(self, t): Set the :class:`~matplotlib.transforms.Transform` instance used by this artist. - ACCEPTS: :class:`~matplotlib.transforms.Transform` instance + ACCEPTS: :class:`~matplotlib.transforms.Transform` instance, or None + set_transform(None) is equivalent to set_transform(IdentityTransform()) """ self._transform = t - self._transformSet = t is not None + self._transformSet = True self.pchanged() def get_transform(self): diff --git a/lib/matplotlib/axes.py b/lib/matplotlib/axes.py index f5c7ba33b146..b0f8913ba4ea 100644 --- a/lib/matplotlib/axes.py +++ b/lib/matplotlib/axes.py @@ -6637,7 +6637,7 @@ def stackplot(self, x, *args, **kwargs): def streamplot(self, x, y, u, v, density=1, linewidth=None, color=None, cmap=None, norm=None, arrowsize=1, arrowstyle='-|>', - minlength=0.1, transform=None): + minlength=0.1, transform=False): if not self._hold: self.cla() stream_container = mstream.streamplot(self, x, y, u, v, density=density, diff --git a/lib/matplotlib/collections.py b/lib/matplotlib/collections.py index 1a0410be7ebb..8cba02539b5c 100644 --- a/lib/matplotlib/collections.py +++ b/lib/matplotlib/collections.py @@ -23,7 +23,7 @@ import matplotlib.backend_bases as backend_bases import matplotlib.path as mpath import matplotlib.mlab as mlab - +from matplotlib.transforms import IdentityTransform class Collection(artist.Artist, cm.ScalarMappable): """ @@ -81,7 +81,7 @@ def __init__(self, linestyles='solid', antialiaseds=None, offsets=None, - transOffset=None, + transOffset=False, # disginguish from None(=IdentityTransform) norm=None, # optional for ScalarMappable cmap=None, # ditto pickradius=5.0, @@ -115,7 +115,7 @@ def __init__(self, if offsets is not None: offsets = np.asanyarray(offsets) offsets.shape = (-1, 2) # Make it Nx2 - if transOffset is not None: + if transOffset is not False: self._offsets = offsets self._transOffset = transOffset else: @@ -159,7 +159,7 @@ def get_transforms(self): return self._transforms def get_offset_transform(self): - t = self._transOffset + t = self._transOffset or IdentityTransform() if (not isinstance(t, transforms.Transform) and hasattr(t, '_as_mpl_transform')): t = t._as_mpl_transform(self.axes) diff --git a/lib/matplotlib/pyplot.py b/lib/matplotlib/pyplot.py index 997382e47d44..778492dbaa95 100644 --- a/lib/matplotlib/pyplot.py +++ b/lib/matplotlib/pyplot.py @@ -2253,7 +2253,7 @@ def acorr(x, hold=None, **kwargs): ax = gca() # allow callers to override the hold state by passing hold=True|False washold = ax.ishold() - + if hold is not None: ax.hold(hold) try: @@ -2261,7 +2261,7 @@ def acorr(x, hold=None, **kwargs): draw_if_interactive() finally: ax.hold(washold) - + return ret # This function was autogenerated by boilerplate.py. Do not edit as @@ -2271,7 +2271,7 @@ def arrow(x, y, dx, dy, hold=None, **kwargs): ax = gca() # allow callers to override the hold state by passing hold=True|False washold = ax.ishold() - + if hold is not None: ax.hold(hold) try: @@ -2279,7 +2279,7 @@ def arrow(x, y, dx, dy, hold=None, **kwargs): draw_if_interactive() finally: ax.hold(washold) - + return ret # This function was autogenerated by boilerplate.py. Do not edit as @@ -2289,7 +2289,7 @@ def axhline(y=0, xmin=0, xmax=1, hold=None, **kwargs): ax = gca() # allow callers to override the hold state by passing hold=True|False washold = ax.ishold() - + if hold is not None: ax.hold(hold) try: @@ -2297,7 +2297,7 @@ def axhline(y=0, xmin=0, xmax=1, hold=None, **kwargs): draw_if_interactive() finally: ax.hold(washold) - + return ret # This function was autogenerated by boilerplate.py. Do not edit as @@ -2307,7 +2307,7 @@ def axhspan(ymin, ymax, xmin=0, xmax=1, hold=None, **kwargs): ax = gca() # allow callers to override the hold state by passing hold=True|False washold = ax.ishold() - + if hold is not None: ax.hold(hold) try: @@ -2315,7 +2315,7 @@ def axhspan(ymin, ymax, xmin=0, xmax=1, hold=None, **kwargs): draw_if_interactive() finally: ax.hold(washold) - + return ret # This function was autogenerated by boilerplate.py. Do not edit as @@ -2325,7 +2325,7 @@ def axvline(x=0, ymin=0, ymax=1, hold=None, **kwargs): ax = gca() # allow callers to override the hold state by passing hold=True|False washold = ax.ishold() - + if hold is not None: ax.hold(hold) try: @@ -2333,7 +2333,7 @@ def axvline(x=0, ymin=0, ymax=1, hold=None, **kwargs): draw_if_interactive() finally: ax.hold(washold) - + return ret # This function was autogenerated by boilerplate.py. Do not edit as @@ -2343,7 +2343,7 @@ def axvspan(xmin, xmax, ymin=0, ymax=1, hold=None, **kwargs): ax = gca() # allow callers to override the hold state by passing hold=True|False washold = ax.ishold() - + if hold is not None: ax.hold(hold) try: @@ -2351,7 +2351,7 @@ def axvspan(xmin, xmax, ymin=0, ymax=1, hold=None, **kwargs): draw_if_interactive() finally: ax.hold(washold) - + return ret # This function was autogenerated by boilerplate.py. Do not edit as @@ -2361,7 +2361,7 @@ def bar(left, height, width=0.8, bottom=None, hold=None, **kwargs): ax = gca() # allow callers to override the hold state by passing hold=True|False washold = ax.ishold() - + if hold is not None: ax.hold(hold) try: @@ -2369,7 +2369,7 @@ def bar(left, height, width=0.8, bottom=None, hold=None, **kwargs): draw_if_interactive() finally: ax.hold(washold) - + return ret # This function was autogenerated by boilerplate.py. Do not edit as @@ -2379,7 +2379,7 @@ def barh(bottom, width, height=0.8, left=None, hold=None, **kwargs): ax = gca() # allow callers to override the hold state by passing hold=True|False washold = ax.ishold() - + if hold is not None: ax.hold(hold) try: @@ -2387,7 +2387,7 @@ def barh(bottom, width, height=0.8, left=None, hold=None, **kwargs): draw_if_interactive() finally: ax.hold(washold) - + return ret # This function was autogenerated by boilerplate.py. Do not edit as @@ -2397,7 +2397,7 @@ def broken_barh(xranges, yrange, hold=None, **kwargs): ax = gca() # allow callers to override the hold state by passing hold=True|False washold = ax.ishold() - + if hold is not None: ax.hold(hold) try: @@ -2405,7 +2405,7 @@ def broken_barh(xranges, yrange, hold=None, **kwargs): draw_if_interactive() finally: ax.hold(washold) - + return ret # This function was autogenerated by boilerplate.py. Do not edit as @@ -2417,7 +2417,7 @@ def boxplot(x, notch=False, sym='b+', vert=True, whis=1.5, positions=None, ax = gca() # allow callers to override the hold state by passing hold=True|False washold = ax.ishold() - + if hold is not None: ax.hold(hold) try: @@ -2428,7 +2428,7 @@ def boxplot(x, notch=False, sym='b+', vert=True, whis=1.5, positions=None, draw_if_interactive() finally: ax.hold(washold) - + return ret # This function was autogenerated by boilerplate.py. Do not edit as @@ -2440,7 +2440,7 @@ def cohere(x, y, NFFT=256, Fs=2, Fc=0, detrend=mlab.detrend_none, ax = gca() # allow callers to override the hold state by passing hold=True|False washold = ax.ishold() - + if hold is not None: ax.hold(hold) try: @@ -2450,7 +2450,7 @@ def cohere(x, y, NFFT=256, Fs=2, Fc=0, detrend=mlab.detrend_none, draw_if_interactive() finally: ax.hold(washold) - + return ret # This function was autogenerated by boilerplate.py. Do not edit as @@ -2468,7 +2468,7 @@ def clabel(CS, *args, **kwargs): draw_if_interactive() finally: ax.hold(washold) - + return ret # This function was autogenerated by boilerplate.py. Do not edit as @@ -2516,7 +2516,7 @@ def csd(x, y, NFFT=256, Fs=2, Fc=0, detrend=mlab.detrend_none, ax = gca() # allow callers to override the hold state by passing hold=True|False washold = ax.ishold() - + if hold is not None: ax.hold(hold) try: @@ -2526,7 +2526,7 @@ def csd(x, y, NFFT=256, Fs=2, Fc=0, detrend=mlab.detrend_none, draw_if_interactive() finally: ax.hold(washold) - + return ret # This function was autogenerated by boilerplate.py. Do not edit as @@ -2539,7 +2539,7 @@ def errorbar(x, y, yerr=None, xerr=None, fmt='-', ecolor=None, elinewidth=None, ax = gca() # allow callers to override the hold state by passing hold=True|False washold = ax.ishold() - + if hold is not None: ax.hold(hold) try: @@ -2551,7 +2551,7 @@ def errorbar(x, y, yerr=None, xerr=None, fmt='-', ecolor=None, elinewidth=None, draw_if_interactive() finally: ax.hold(washold) - + return ret # This function was autogenerated by boilerplate.py. Do not edit as @@ -2569,7 +2569,7 @@ def fill(*args, **kwargs): draw_if_interactive() finally: ax.hold(washold) - + return ret # This function was autogenerated by boilerplate.py. Do not edit as @@ -2579,7 +2579,7 @@ def fill_between(x, y1, y2=0, where=None, interpolate=False, hold=None, **kwargs ax = gca() # allow callers to override the hold state by passing hold=True|False washold = ax.ishold() - + if hold is not None: ax.hold(hold) try: @@ -2588,7 +2588,7 @@ def fill_between(x, y1, y2=0, where=None, interpolate=False, hold=None, **kwargs draw_if_interactive() finally: ax.hold(washold) - + return ret # This function was autogenerated by boilerplate.py. Do not edit as @@ -2598,7 +2598,7 @@ def fill_betweenx(y, x1, x2=0, where=None, hold=None, **kwargs): ax = gca() # allow callers to override the hold state by passing hold=True|False washold = ax.ishold() - + if hold is not None: ax.hold(hold) try: @@ -2606,7 +2606,7 @@ def fill_betweenx(y, x1, x2=0, where=None, hold=None, **kwargs): draw_if_interactive() finally: ax.hold(washold) - + return ret # This function was autogenerated by boilerplate.py. Do not edit as @@ -2620,7 +2620,7 @@ def hexbin(x, y, C=None, gridsize=100, bins=None, xscale='linear', ax = gca() # allow callers to override the hold state by passing hold=True|False washold = ax.ishold() - + if hold is not None: ax.hold(hold) try: @@ -2646,7 +2646,7 @@ def hist(x, bins=10, range=None, normed=False, weights=None, cumulative=False, ax = gca() # allow callers to override the hold state by passing hold=True|False washold = ax.ishold() - + if hold is not None: ax.hold(hold) try: @@ -2658,7 +2658,7 @@ def hist(x, bins=10, range=None, normed=False, weights=None, cumulative=False, draw_if_interactive() finally: ax.hold(washold) - + return ret # This function was autogenerated by boilerplate.py. Do not edit as @@ -2669,7 +2669,7 @@ def hist2d(x, y, bins=10, range=None, normed=False, weights=None, cmin=None, ax = gca() # allow callers to override the hold state by passing hold=True|False washold = ax.ishold() - + if hold is not None: ax.hold(hold) try: @@ -2689,7 +2689,7 @@ def hlines(y, xmin, xmax, colors='k', linestyles='solid', label='', hold=None, ax = gca() # allow callers to override the hold state by passing hold=True|False washold = ax.ishold() - + if hold is not None: ax.hold(hold) try: @@ -2698,7 +2698,7 @@ def hlines(y, xmin, xmax, colors='k', linestyles='solid', label='', hold=None, draw_if_interactive() finally: ax.hold(washold) - + return ret # This function was autogenerated by boilerplate.py. Do not edit as @@ -2711,7 +2711,7 @@ def imshow(X, cmap=None, norm=None, aspect=None, interpolation=None, alpha=None, ax = gca() # allow callers to override the hold state by passing hold=True|False washold = ax.ishold() - + if hold is not None: ax.hold(hold) try: @@ -2741,7 +2741,7 @@ def loglog(*args, **kwargs): draw_if_interactive() finally: ax.hold(washold) - + return ret # This function was autogenerated by boilerplate.py. Do not edit as @@ -2789,7 +2789,7 @@ def pie(x, explode=None, labels=None, colors=None, autopct=None, ax = gca() # allow callers to override the hold state by passing hold=True|False washold = ax.ishold() - + if hold is not None: ax.hold(hold) try: @@ -2800,7 +2800,7 @@ def pie(x, explode=None, labels=None, colors=None, autopct=None, draw_if_interactive() finally: ax.hold(washold) - + return ret # This function was autogenerated by boilerplate.py. Do not edit as @@ -2818,7 +2818,7 @@ def plot(*args, **kwargs): draw_if_interactive() finally: ax.hold(washold) - + return ret # This function was autogenerated by boilerplate.py. Do not edit as @@ -2829,7 +2829,7 @@ def plot_date(x, y, fmt='bo', tz=None, xdate=True, ydate=False, hold=None, ax = gca() # allow callers to override the hold state by passing hold=True|False washold = ax.ishold() - + if hold is not None: ax.hold(hold) try: @@ -2838,7 +2838,7 @@ def plot_date(x, y, fmt='bo', tz=None, xdate=True, ydate=False, hold=None, draw_if_interactive() finally: ax.hold(washold) - + return ret # This function was autogenerated by boilerplate.py. Do not edit as @@ -2850,7 +2850,7 @@ def psd(x, NFFT=256, Fs=2, Fc=0, detrend=mlab.detrend_none, ax = gca() # allow callers to override the hold state by passing hold=True|False washold = ax.ishold() - + if hold is not None: ax.hold(hold) try: @@ -2860,7 +2860,7 @@ def psd(x, NFFT=256, Fs=2, Fc=0, detrend=mlab.detrend_none, draw_if_interactive() finally: ax.hold(washold) - + return ret # This function was autogenerated by boilerplate.py. Do not edit as @@ -2896,7 +2896,7 @@ def quiverkey(*args, **kw): draw_if_interactive() finally: ax.hold(washold) - + return ret # This function was autogenerated by boilerplate.py. Do not edit as @@ -2908,7 +2908,7 @@ def scatter(x, y, s=20, c='b', marker='o', cmap=None, norm=None, vmin=None, ax = gca() # allow callers to override the hold state by passing hold=True|False washold = ax.ishold() - + if hold is not None: ax.hold(hold) try: @@ -2937,7 +2937,7 @@ def semilogx(*args, **kwargs): draw_if_interactive() finally: ax.hold(washold) - + return ret # This function was autogenerated by boilerplate.py. Do not edit as @@ -2955,7 +2955,7 @@ def semilogy(*args, **kwargs): draw_if_interactive() finally: ax.hold(washold) - + return ret # This function was autogenerated by boilerplate.py. Do not edit as @@ -2968,7 +2968,7 @@ def specgram(x, NFFT=256, Fs=2, Fc=0, detrend=mlab.detrend_none, ax = gca() # allow callers to override the hold state by passing hold=True|False washold = ax.ishold() - + if hold is not None: ax.hold(hold) try: @@ -3008,7 +3008,7 @@ def stem(x, y, linefmt='b-', markerfmt='bo', basefmt='r-', bottom=None, ax = gca() # allow callers to override the hold state by passing hold=True|False washold = ax.ishold() - + if hold is not None: ax.hold(hold) try: @@ -3017,7 +3017,7 @@ def stem(x, y, linefmt='b-', markerfmt='bo', basefmt='r-', bottom=None, draw_if_interactive() finally: ax.hold(washold) - + return ret # This function was autogenerated by boilerplate.py. Do not edit as @@ -3035,7 +3035,7 @@ def step(x, y, *args, **kwargs): draw_if_interactive() finally: ax.hold(washold) - + return ret # This function was autogenerated by boilerplate.py. Do not edit as @@ -3043,11 +3043,11 @@ def step(x, y, *args, **kwargs): @_autogen_docstring(Axes.streamplot) def streamplot(x, y, u, v, density=1, linewidth=None, color=None, cmap=None, norm=None, arrowsize=1, arrowstyle='-|>', minlength=0.1, - transform=None, hold=None): + transform=False, hold=None): ax = gca() # allow callers to override the hold state by passing hold=True|False washold = ax.ishold() - + if hold is not None: ax.hold(hold) try: @@ -3130,7 +3130,7 @@ def triplot(*args, **kwargs): draw_if_interactive() finally: ax.hold(washold) - + return ret # This function was autogenerated by boilerplate.py. Do not edit as @@ -3141,7 +3141,7 @@ def vlines(x, ymin, ymax, colors='k', linestyles='solid', label='', hold=None, ax = gca() # allow callers to override the hold state by passing hold=True|False washold = ax.ishold() - + if hold is not None: ax.hold(hold) try: @@ -3150,7 +3150,7 @@ def vlines(x, ymin, ymax, colors='k', linestyles='solid', label='', hold=None, draw_if_interactive() finally: ax.hold(washold) - + return ret # This function was autogenerated by boilerplate.py. Do not edit as @@ -3161,7 +3161,7 @@ def xcorr(x, y, normed=True, detrend=mlab.detrend_none, usevlines=True, ax = gca() # allow callers to override the hold state by passing hold=True|False washold = ax.ishold() - + if hold is not None: ax.hold(hold) try: @@ -3170,7 +3170,7 @@ def xcorr(x, y, normed=True, detrend=mlab.detrend_none, usevlines=True, draw_if_interactive() finally: ax.hold(washold) - + return ret # This function was autogenerated by boilerplate.py. Do not edit as @@ -3188,7 +3188,7 @@ def barbs(*args, **kw): draw_if_interactive() finally: ax.hold(washold) - + return ret # This function was autogenerated by boilerplate.py. Do not edit as diff --git a/lib/matplotlib/streamplot.py b/lib/matplotlib/streamplot.py index bc611daa9675..e20928240a8c 100644 --- a/lib/matplotlib/streamplot.py +++ b/lib/matplotlib/streamplot.py @@ -16,7 +16,7 @@ def streamplot(axes, x, y, u, v, density=1, linewidth=None, color=None, cmap=None, norm=None, arrowsize=1, arrowstyle='-|>', - minlength=0.1, transform=None): + minlength=0.1, transform=False): """Draws streamlines of a vector flow. *x*, *y* : 1d arrays @@ -47,6 +47,9 @@ def streamplot(axes, x, y, u, v, density=1, linewidth=None, color=None, See :class:`~matplotlib.patches.FancyArrowPatch`. *minlength* : float Minimum length of streamline in axes coordinates. + *transform* : :class:`~matplotlib.transforms.Transform` + Transformation object to use. Specifying `None` uses + device coordinates. The default is to use the axes' `transData`. Returns: @@ -71,6 +74,9 @@ def streamplot(axes, x, y, u, v, density=1, linewidth=None, color=None, if linewidth is None: linewidth = matplotlib.rcParams['lines.linewidth'] + if transform == False: # transform=None is a valid setting + transform = axes.transData + line_kw = {} arrow_kw = dict(arrowstyle=arrowstyle, mutation_scale=10 * arrowsize) diff --git a/lib/matplotlib/tests/test_transform_none.py b/lib/matplotlib/tests/test_transform_none.py new file mode 100644 index 000000000000..102869f487d1 --- /dev/null +++ b/lib/matplotlib/tests/test_transform_none.py @@ -0,0 +1,63 @@ +from nose.tools import assert_equal + +import matplotlib.pyplot as plt +from matplotlib.artist import Artist +from matplotlib.collections import Collection +from matplotlib.patches import Ellipse, Rectangle +from matplotlib.transforms import IdentityTransform +from matplotlib.streamplot import streamplot +import numpy as np + + +def assert_transforms_equal(t1, t2): + assert_equal(t1.to_values(), t2.to_values()) + + +def test_transform_none(): + """ + Supplying transform=None to an artist should use device + coordinates (i.e. transforms.IdentityTransform). + """ + + ax = plt.gca() + + #artists + t = IdentityTransform() + a = Artist() + a.set_transform(None) + assert_transforms_equal(a.get_transform(), t) + + a = Artist() + a.update({'transform': None}) + assert_transforms_equal(a.get_transform(), t) + + e = Ellipse((0, 0), width=100, height=100, transform=None) + assert_transforms_equal(Artist.get_transform(e), t) + + b = Rectangle((0, 0), width=40, height=40, transform=None, fc='r') + assert_transforms_equal(Artist.get_transform(b), t) + + line, = ax.plot([1], [2], transform=None) + assert_transforms_equal(line.get_transform(), t) + + #collections + c = Collection() + c.set_transform(None) + assert_transforms_equal(c.get_transform(), t) + + points = ax.scatter([0], [1], transform=None) + assert_transforms_equal(points.get_transform(), t) + + #misc + x = np.array([1, 2, 3]) + y = x + u = np.array([[1, 1, 1], [1, 1, 1], [1, 1, 1]]) + v = u + s1 = streamplot(ax, x, y, u, v, transform=None) + s2 = ax.streamplot(x, y, u, -v, color='m', transform=None) + + assert_transforms_equal(s1.lines.get_transform(), t) + assert_transforms_equal(s2.lines.get_transform(), t) + + assert_transforms_equal(s1.arrows.get_transform(), t) + assert_transforms_equal(s2.arrows.get_transform(), t)