diff --git a/doc/api/axis_api.rst b/doc/api/axis_api.rst index afea7afff682..56a2ea6d4ce9 100644 --- a/doc/api/axis_api.rst +++ b/doc/api/axis_api.rst @@ -109,8 +109,8 @@ Ticks, tick labels and Offset text Axis.axis_date -Data and view internvals ------------------------- +Data and view intervals +----------------------- .. autosummary:: :toctree: _as_gen diff --git a/examples/animation/unchained.py b/examples/animation/unchained.py index d4f164b2263f..faa2cf0a29c1 100644 --- a/examples/animation/unchained.py +++ b/examples/animation/unchained.py @@ -25,7 +25,7 @@ # Generate random data data = np.random.uniform(0, 1, (64, 75)) X = np.linspace(-1, 1, data.shape[-1]) -G = 1.5 * np.exp(-4 * X * X) +G = 1.5 * np.exp(-4 * X ** 2) # Generate line plots lines = [] diff --git a/examples/api/custom_projection_example.py b/examples/api/custom_projection_example.py index 1747027146ba..588b572441af 100644 --- a/examples/api/custom_projection_example.py +++ b/examples/api/custom_projection_example.py @@ -434,15 +434,11 @@ def __init__(self, resolution): self._resolution = resolution def transform_non_affine(self, xy): - x = xy[:, 0:1] - y = xy[:, 1:2] - - quarter_x = 0.25 * x - half_y = 0.5 * y - z = np.sqrt(1.0 - quarter_x*quarter_x - half_y*half_y) - longitude = 2 * np.arctan((z*x) / (2.0 * (2.0*z*z - 1.0))) + x, y = xy.T + z = np.sqrt(1 - (x / 4) ** 2 - (y / 2) ** 2) + longitude = 2 * np.arctan((z * x) / (2 * (2 * z ** 2 - 1))) latitude = np.arcsin(y*z) - return np.concatenate((longitude, latitude), 1) + return np.column_stack([longitude, latitude]) transform_non_affine.__doc__ = Transform.transform_non_affine.__doc__ def inverted(self): diff --git a/examples/api/scatter_piecharts.py b/examples/api/scatter_piecharts.py index 8d401ec497c3..6e03994e6de8 100644 --- a/examples/api/scatter_piecharts.py +++ b/examples/api/scatter_piecharts.py @@ -7,7 +7,7 @@ Thanks to Manuel Metz for the example """ -import math + import numpy as np import matplotlib.pyplot as plt @@ -16,35 +16,33 @@ r2 = r1 + 0.4 # 40% # define some sizes of the scatter marker -sizes = [60, 80, 120] +sizes = np.array([60, 80, 120]) # calculate the points of the first pie marker # # these are just the origin (0,0) + # some points on a circle cos,sin -x = [0] + np.cos(np.linspace(0, 2*math.pi*r1, 10)).tolist() -y = [0] + np.sin(np.linspace(0, 2*math.pi*r1, 10)).tolist() - +x = [0] + np.cos(np.linspace(0, 2 * np.pi * r1, 10)).tolist() +y = [0] + np.sin(np.linspace(0, 2 * np.pi * r1, 10)).tolist() xy1 = list(zip(x, y)) -s1 = max(max(x), max(y)) +s1 = np.max(xy1) -# ... -x = [0] + np.cos(np.linspace(2*math.pi*r1, 2*math.pi*r2, 10)).tolist() -y = [0] + np.sin(np.linspace(2*math.pi*r1, 2*math.pi*r2, 10)).tolist() +x = [0] + np.cos(np.linspace(2 * np.pi * r1, 2 * np.pi * r2, 10)).tolist() +y = [0] + np.sin(np.linspace(2 * np.pi * r1, 2 * np.pi * r2, 10)).tolist() xy2 = list(zip(x, y)) -s2 = max(max(x), max(y)) +s2 = np.max(xy2) -x = [0] + np.cos(np.linspace(2*math.pi*r2, 2*math.pi, 10)).tolist() -y = [0] + np.sin(np.linspace(2*math.pi*r2, 2*math.pi, 10)).tolist() +x = [0] + np.cos(np.linspace(2 * np.pi * r2, 2 * np.pi, 10)).tolist() +y = [0] + np.sin(np.linspace(2 * np.pi * r2, 2 * np.pi, 10)).tolist() xy3 = list(zip(x, y)) -s3 = max(max(x), max(y)) +s3 = np.max(xy3) fig, ax = plt.subplots() -ax.scatter(np.arange(3), np.arange(3), marker=(xy1, 0), - s=[s1*s1*_ for _ in sizes], facecolor='blue') -ax.scatter(np.arange(3), np.arange(3), marker=(xy2, 0), - s=[s2*s2*_ for _ in sizes], facecolor='green') -ax.scatter(np.arange(3), np.arange(3), marker=(xy3, 0), - s=[s3*s3*_ for _ in sizes], facecolor='red') +ax.scatter(range(3), range(3), marker=(xy1, 0), + s=s1 ** 2 * sizes, facecolor='blue') +ax.scatter(range(3), range(3), marker=(xy2, 0), + s=s2 ** 2 * sizes, facecolor='green') +ax.scatter(range(3), range(3), marker=(xy3, 0), + s=s3 ** 2 * sizes, facecolor='red') plt.show() diff --git a/examples/event_handling/timers.py b/examples/event_handling/timers.py index b9b82ee8c179..aba9393699dd 100644 --- a/examples/event_handling/timers.py +++ b/examples/event_handling/timers.py @@ -18,7 +18,7 @@ def update_title(axes): fig, ax = plt.subplots() x = np.linspace(-3, 3) -ax.plot(x, x*x) +ax.plot(x, x ** 2) # Create a new timer object. Set the interval to 100 milliseconds # (1000 is default) and tell the timer what function should be called. diff --git a/examples/event_handling/trifinder_event_demo.py b/examples/event_handling/trifinder_event_demo.py index 4232e96a5e73..7d21e8da43cc 100644 --- a/examples/event_handling/trifinder_event_demo.py +++ b/examples/event_handling/trifinder_event_demo.py @@ -11,16 +11,15 @@ from matplotlib.tri import Triangulation from matplotlib.patches import Polygon import numpy as np -import math def update_polygon(tri): if tri == -1: points = [0, 0, 0] else: - points = triangulation.triangles[tri] - xs = triangulation.x[points] - ys = triangulation.y[points] + points = triang.triangles[tri] + xs = triang.x[points] + ys = triang.y[points] polygon.set_xy(list(zip(xs, ys))) @@ -39,23 +38,22 @@ def motion_notify(event): n_radii = 5 min_radius = 0.25 radii = np.linspace(min_radius, 0.95, n_radii) -angles = np.linspace(0, 2*math.pi, n_angles, endpoint=False) +angles = np.linspace(0, 2 * np.pi, n_angles, endpoint=False) angles = np.repeat(angles[..., np.newaxis], n_radii, axis=1) -angles[:, 1::2] += math.pi / n_angles +angles[:, 1::2] += np.pi / n_angles x = (radii*np.cos(angles)).flatten() y = (radii*np.sin(angles)).flatten() -triangulation = Triangulation(x, y) -xmid = x[triangulation.triangles].mean(axis=1) -ymid = y[triangulation.triangles].mean(axis=1) -mask = np.where(xmid*xmid + ymid*ymid < min_radius*min_radius, 1, 0) -triangulation.set_mask(mask) +triang = Triangulation(x, y) +triang.set_mask(np.hypot(x[triang.triangles].mean(axis=1), + y[triang.triangles].mean(axis=1)) + < min_radius) # Use the triangulation's default TriFinder object. -trifinder = triangulation.get_trifinder() +trifinder = triang.get_trifinder() # Setup plot and callbacks. plt.subplot(111, aspect='equal') -plt.triplot(triangulation, 'bo-') +plt.triplot(triang, 'bo-') polygon = Polygon([[0, 0], [0, 0]], facecolor='y') # dummy data for xs,ys update_polygon(-1) plt.gca().add_patch(polygon) diff --git a/examples/images_contours_and_fields/tricontour_demo.py b/examples/images_contours_and_fields/tricontour_demo.py index bcd6d9b9abf2..47f8f74411ed 100644 --- a/examples/images_contours_and_fields/tricontour_demo.py +++ b/examples/images_contours_and_fields/tricontour_demo.py @@ -8,7 +8,6 @@ import matplotlib.pyplot as plt import matplotlib.tri as tri import numpy as np -import math ############################################################################### # Creating a Triangulation without specifying the triangles results in the @@ -20,22 +19,21 @@ min_radius = 0.25 radii = np.linspace(min_radius, 0.95, n_radii) -angles = np.linspace(0, 2 * math.pi, n_angles, endpoint=False) +angles = np.linspace(0, 2 * np.pi, n_angles, endpoint=False) angles = np.repeat(angles[..., np.newaxis], n_radii, axis=1) -angles[:, 1::2] += math.pi / n_angles +angles[:, 1::2] += np.pi / n_angles x = (radii * np.cos(angles)).flatten() y = (radii * np.sin(angles)).flatten() -z = (np.cos(radii) * np.cos(angles * 3.0)).flatten() +z = (np.cos(radii) * np.cos(3 * angles)).flatten() # Create the Triangulation; no triangles so Delaunay triangulation created. triang = tri.Triangulation(x, y) # Mask off unwanted triangles. -xmid = x[triang.triangles].mean(axis=1) -ymid = y[triang.triangles].mean(axis=1) -mask = np.where(xmid * xmid + ymid * ymid < min_radius * min_radius, 1, 0) -triang.set_mask(mask) +triang.set_mask(np.hypot(x[triang.triangles].mean(axis=1), + y[triang.triangles].mean(axis=1)) + < min_radius) ############################################################################### # pcolor plot. diff --git a/examples/images_contours_and_fields/tricontour_smooth_user.py b/examples/images_contours_and_fields/tricontour_smooth_user.py index 2523fc18d7e7..b51bcb0596cd 100644 --- a/examples/images_contours_and_fields/tricontour_smooth_user.py +++ b/examples/images_contours_and_fields/tricontour_smooth_user.py @@ -10,7 +10,6 @@ import matplotlib.pyplot as plt import matplotlib.cm as cm import numpy as np -import math #----------------------------------------------------------------------------- @@ -36,9 +35,9 @@ def function_z(x, y): min_radius = 0.15 radii = np.linspace(min_radius, 0.95, n_radii) -angles = np.linspace(0, 2 * math.pi, n_angles, endpoint=False) +angles = np.linspace(0, 2 * np.pi, n_angles, endpoint=False) angles = np.repeat(angles[..., np.newaxis], n_radii, axis=1) -angles[:, 1::2] += math.pi / n_angles +angles[:, 1::2] += np.pi / n_angles x = (radii * np.cos(angles)).flatten() y = (radii * np.sin(angles)).flatten() @@ -50,10 +49,9 @@ def function_z(x, y): triang = tri.Triangulation(x, y) # Mask off unwanted triangles. -xmid = x[triang.triangles].mean(axis=1) -ymid = y[triang.triangles].mean(axis=1) -mask = np.where(xmid * xmid + ymid * ymid < min_radius * min_radius, 1, 0) -triang.set_mask(mask) +triang.set_mask(np.hypot(x[triang.triangles].mean(axis=1), + y[triang.triangles].mean(axis=1)) + < min_radius) #----------------------------------------------------------------------------- # Refine data diff --git a/examples/images_contours_and_fields/trigradient_demo.py b/examples/images_contours_and_fields/trigradient_demo.py index 9470c51126d7..911b49402762 100644 --- a/examples/images_contours_and_fields/trigradient_demo.py +++ b/examples/images_contours_and_fields/trigradient_demo.py @@ -5,12 +5,11 @@ Demonstrates computation of gradient with matplotlib.tri.CubicTriInterpolator. """ -from matplotlib.tri import Triangulation, UniformTriRefiner,\ - CubicTriInterpolator +from matplotlib.tri import ( + Triangulation, UniformTriRefiner, CubicTriInterpolator) import matplotlib.pyplot as plt import matplotlib.cm as cm import numpy as np -import math #----------------------------------------------------------------------------- @@ -33,9 +32,9 @@ def dipole_potential(x, y): min_radius = 0.2 radii = np.linspace(min_radius, 0.95, n_radii) -angles = np.linspace(0, 2*math.pi, n_angles, endpoint=False) +angles = np.linspace(0, 2 * np.pi, n_angles, endpoint=False) angles = np.repeat(angles[..., np.newaxis], n_radii, axis=1) -angles[:, 1::2] += math.pi/n_angles +angles[:, 1::2] += np.pi / n_angles x = (radii*np.cos(angles)).flatten() y = (radii*np.sin(angles)).flatten() @@ -46,10 +45,9 @@ def dipole_potential(x, y): triang = Triangulation(x, y) # Mask off unwanted triangles. -xmid = x[triang.triangles].mean(axis=1) -ymid = y[triang.triangles].mean(axis=1) -mask = np.where(xmid*xmid + ymid*ymid < min_radius*min_radius, 1, 0) -triang.set_mask(mask) +triang.set_mask(np.hypot(x[triang.triangles].mean(axis=1), + y[triang.triangles].mean(axis=1)) + < min_radius) #----------------------------------------------------------------------------- # Refine data - interpolates the electrical potential V diff --git a/examples/images_contours_and_fields/tripcolor_demo.py b/examples/images_contours_and_fields/tripcolor_demo.py index d2f95a99f2fe..8c885744895d 100644 --- a/examples/images_contours_and_fields/tripcolor_demo.py +++ b/examples/images_contours_and_fields/tripcolor_demo.py @@ -8,7 +8,6 @@ import matplotlib.pyplot as plt import matplotlib.tri as tri import numpy as np -import math ############################################################################### # Creating a Triangulation without specifying the triangles results in the @@ -20,22 +19,21 @@ min_radius = 0.25 radii = np.linspace(min_radius, 0.95, n_radii) -angles = np.linspace(0, 2 * math.pi, n_angles, endpoint=False) +angles = np.linspace(0, 2 * np.pi, n_angles, endpoint=False) angles = np.repeat(angles[..., np.newaxis], n_radii, axis=1) -angles[:, 1::2] += math.pi / n_angles +angles[:, 1::2] += np.pi / n_angles x = (radii * np.cos(angles)).flatten() y = (radii * np.sin(angles)).flatten() -z = (np.cos(radii) * np.cos(angles * 3.0)).flatten() +z = (np.cos(radii) * np.cos(3 * angles)).flatten() # Create the Triangulation; no triangles so Delaunay triangulation created. triang = tri.Triangulation(x, y) # Mask off unwanted triangles. -xmid = x[triang.triangles].mean(axis=1) -ymid = y[triang.triangles].mean(axis=1) -mask = np.where(xmid * xmid + ymid * ymid < min_radius * min_radius, 1, 0) -triang.set_mask(mask) +triang.set_mask(np.hypot(x[triang.triangles].mean(axis=1), + y[triang.triangles].mean(axis=1)) + < min_radius) ############################################################################### # tripcolor plot. diff --git a/examples/images_contours_and_fields/triplot_demo.py b/examples/images_contours_and_fields/triplot_demo.py index b160026e899d..d3a65762d021 100644 --- a/examples/images_contours_and_fields/triplot_demo.py +++ b/examples/images_contours_and_fields/triplot_demo.py @@ -8,7 +8,6 @@ import matplotlib.pyplot as plt import matplotlib.tri as tri import numpy as np -import math ############################################################################### # Creating a Triangulation without specifying the triangles results in the @@ -20,9 +19,9 @@ min_radius = 0.25 radii = np.linspace(min_radius, 0.95, n_radii) -angles = np.linspace(0, 2 * math.pi, n_angles, endpoint=False) +angles = np.linspace(0, 2 * np.pi, n_angles, endpoint=False) angles = np.repeat(angles[..., np.newaxis], n_radii, axis=1) -angles[:, 1::2] += math.pi / n_angles +angles[:, 1::2] += np.pi / n_angles x = (radii * np.cos(angles)).flatten() y = (radii * np.sin(angles)).flatten() @@ -31,10 +30,9 @@ triang = tri.Triangulation(x, y) # Mask off unwanted triangles. -xmid = x[triang.triangles].mean(axis=1) -ymid = y[triang.triangles].mean(axis=1) -mask = np.where(xmid * xmid + ymid * ymid < min_radius * min_radius, 1, 0) -triang.set_mask(mask) +triang.set_mask(np.hypot(x[triang.triangles].mean(axis=1), + y[triang.triangles].mean(axis=1)) + < min_radius) ############################################################################### # Plot the triangulation. diff --git a/examples/lines_bars_and_markers/nan_test.py b/examples/lines_bars_and_markers/nan_test.py index ad7cd6b5698c..4216f6960ae0 100644 --- a/examples/lines_bars_and_markers/nan_test.py +++ b/examples/lines_bars_and_markers/nan_test.py @@ -9,7 +9,7 @@ import matplotlib.pyplot as plt t = np.arange(0.0, 1.0 + 0.01, 0.01) -s = np.cos(2 * 2 * np.pi * t) +s = np.cos(2 * 2*np.pi * t) t[41:60] = np.nan plt.subplot(2, 1, 1) diff --git a/examples/misc/multipage_pdf.py b/examples/misc/multipage_pdf.py index fd97409087f8..532d771849cb 100644 --- a/examples/misc/multipage_pdf.py +++ b/examples/misc/multipage_pdf.py @@ -35,7 +35,7 @@ plt.rc('text', usetex=False) fig = plt.figure(figsize=(4, 5)) - plt.plot(x, x*x, 'ko') + plt.plot(x, x ** 2, 'ko') plt.title('Page Three') pdf.savefig(fig) # or you can pass a Figure object to pdf.savefig plt.close() diff --git a/examples/misc/pythonic_matplotlib.py b/examples/misc/pythonic_matplotlib.py index 41de00ca259b..07c6fa915a92 100644 --- a/examples/misc/pythonic_matplotlib.py +++ b/examples/misc/pythonic_matplotlib.py @@ -64,7 +64,7 @@ fig = figure(1) ax1 = fig.add_subplot(211) -ax1.plot(t, sin(2*pi*t)) +ax1.plot(t, sin(2*pi * t)) ax1.grid(True) ax1.set_ylim((-2, 2)) ax1.set_ylabel('1 Hz') @@ -74,7 +74,7 @@ ax2 = fig.add_subplot(212) -ax2.plot(t, sin(2*2*pi*t)) +ax2.plot(t, sin(2 * 2*pi * t)) ax2.grid(True) ax2.set_ylim((-2, 2)) l = ax2.set_xlabel('Hi mom') diff --git a/examples/misc/table_demo.py b/examples/misc/table_demo.py index 6b29df44b755..cc23492d5536 100644 --- a/examples/misc/table_demo.py +++ b/examples/misc/table_demo.py @@ -29,7 +29,7 @@ bar_width = 0.4 # Initialize the vertical-offset for the stacked bar chart. -y_offset = np.array([0.0] * len(columns)) +y_offset = np.zeros(len(columns)) # Plot bars and create text labels for the table cell_text = [] diff --git a/examples/mplot3d/tricontour3d.py b/examples/mplot3d/tricontour3d.py index f78ff63c8532..7e9e6971bb62 100644 --- a/examples/mplot3d/tricontour3d.py +++ b/examples/mplot3d/tricontour3d.py @@ -26,16 +26,15 @@ x = (radii*np.cos(angles)).flatten() y = (radii*np.sin(angles)).flatten() -z = (np.cos(radii)*np.cos(angles*3.0)).flatten() +z = (np.cos(radii)*np.cos(3*angles)).flatten() # Create a custom triangulation. triang = tri.Triangulation(x, y) # Mask off unwanted triangles. -xmid = x[triang.triangles].mean(axis=1) -ymid = y[triang.triangles].mean(axis=1) -mask = np.where(xmid*xmid + ymid*ymid < min_radius*min_radius, 1, 0) -triang.set_mask(mask) +triang.set_mask(np.hypot(x[triang.triangles].mean(axis=1), + y[triang.triangles].mean(axis=1)) + < min_radius) fig = plt.figure() ax = fig.gca(projection='3d') diff --git a/examples/mplot3d/tricontourf3d.py b/examples/mplot3d/tricontourf3d.py index 27513f2bd5cd..eebb3ef62e6a 100644 --- a/examples/mplot3d/tricontourf3d.py +++ b/examples/mplot3d/tricontourf3d.py @@ -27,16 +27,15 @@ x = (radii*np.cos(angles)).flatten() y = (radii*np.sin(angles)).flatten() -z = (np.cos(radii)*np.cos(angles*3.0)).flatten() +z = (np.cos(radii)*np.cos(3*angles)).flatten() # Create a custom triangulation. triang = tri.Triangulation(x, y) # Mask off unwanted triangles. -xmid = x[triang.triangles].mean(axis=1) -ymid = y[triang.triangles].mean(axis=1) -mask = np.where(xmid*xmid + ymid*ymid < min_radius*min_radius, 1, 0) -triang.set_mask(mask) +triang.set_mask(np.hypot(x[triang.triangles].mean(axis=1), + y[triang.triangles].mean(axis=1)) + < min_radius) fig = plt.figure() ax = fig.gca(projection='3d') diff --git a/examples/mplot3d/trisurf3d_2.py b/examples/mplot3d/trisurf3d_2.py index 3a6677c76c01..24d19e60b498 100644 --- a/examples/mplot3d/trisurf3d_2.py +++ b/examples/mplot3d/trisurf3d_2.py @@ -61,7 +61,7 @@ # Map radius, angle pairs to x, y, z points. x = (radii*np.cos(angles)).flatten() y = (radii*np.sin(angles)).flatten() -z = (np.cos(radii)*np.cos(angles*3.0)).flatten() +z = (np.cos(radii)*np.cos(3*angles)).flatten() # Create the Triangulation; no triangles so Delaunay triangulation created. triang = mtri.Triangulation(x, y) diff --git a/examples/pyplots/annotation_polar.py b/examples/pyplots/annotation_polar.py index f3b032b7377a..129291aae167 100644 --- a/examples/pyplots/annotation_polar.py +++ b/examples/pyplots/annotation_polar.py @@ -10,7 +10,7 @@ fig = plt.figure() ax = fig.add_subplot(111, polar=True) r = np.arange(0,1,0.001) -theta = 2*2*np.pi*r +theta = 2 * 2*np.pi * r line, = ax.plot(theta, r, color='#ee8d18', lw=3) ind = 800 diff --git a/examples/ticks_and_spines/date_demo_convert.py b/examples/ticks_and_spines/date_demo_convert.py index 43621d00e1b8..e1f266cbe09b 100644 --- a/examples/ticks_and_spines/date_demo_convert.py +++ b/examples/ticks_and_spines/date_demo_convert.py @@ -7,17 +7,17 @@ import datetime import matplotlib.pyplot as plt from matplotlib.dates import DayLocator, HourLocator, DateFormatter, drange -from numpy import arange +import numpy as np date1 = datetime.datetime(2000, 3, 2) date2 = datetime.datetime(2000, 3, 6) delta = datetime.timedelta(hours=6) dates = drange(date1, date2, delta) -y = arange(len(dates) * 1.0) +y = np.arange(len(dates)) fig, ax = plt.subplots() -ax.plot_date(dates, y * y) +ax.plot_date(dates, y ** 2) # this is superfluous, since the autoscaler should get it right, but # use date2num and num2date to convert between dates and floats if @@ -28,7 +28,7 @@ # tick, not the base multiple ax.xaxis.set_major_locator(DayLocator()) -ax.xaxis.set_minor_locator(HourLocator(arange(0, 25, 6))) +ax.xaxis.set_minor_locator(HourLocator(range(0, 25, 6))) ax.xaxis.set_major_formatter(DateFormatter('%Y-%m-%d')) ax.fmt_xdata = DateFormatter('%Y-%m-%d %H:%M:%S') diff --git a/examples/units/basic_units.py b/examples/units/basic_units.py index 6526e394a7c1..be07f0c9fce5 100644 --- a/examples/units/basic_units.py +++ b/examples/units/basic_units.py @@ -4,6 +4,8 @@ =========== """ +import six + import math import numpy as np @@ -108,7 +110,7 @@ def __call__(self, *args): return TaggedValue(ret, ret_unit) -class _TaggedValue(object): +class TaggedValue(six.with_metaclass(TaggedValueMeta)): _proxies = {'__add__': ConvertAllProxy, '__sub__': ConvertAllProxy, @@ -140,18 +142,15 @@ def __init__(self, value, unit): self.proxy_target = self.value def __getattribute__(self, name): - if (name.startswith('__')): + if name.startswith('__'): return object.__getattribute__(self, name) variable = object.__getattribute__(self, 'value') - if (hasattr(variable, name) and name not in self.__class__.__dict__): + if hasattr(variable, name) and name not in self.__class__.__dict__: return getattr(variable, name) return object.__getattribute__(self, name) - def __array__(self, t=None, context=None): - if t is not None: - return np.asarray(self.value).astype(t) - else: - return np.asarray(self.value, 'O') + def __array__(self, dtype=object): + return np.asarray(self.value).astype(dtype) def __array_wrap__(self, array, context): return TaggedValue(array, self.unit) @@ -166,23 +165,17 @@ def __len__(self): return len(self.value) def __iter__(self): - class IteratorProxy(object): - def __init__(self, iter, unit): - self.iter = iter - self.unit = unit - - def __next__(self): - value = next(self.iter) - return TaggedValue(value, self.unit) - next = __next__ # for Python 2 - return IteratorProxy(iter(self.value), self.unit) + # Return a generator expression rather than use `yield`, so that + # TypeError is raised by iter(self) if appropriate when checking for + # iterability. + return (TaggedValue(inner, self.unit) for inner in self.value) def get_compressed_copy(self, mask): new_value = np.ma.masked_array(self.value, mask=mask).compressed() return TaggedValue(new_value, self.unit) def convert_to(self, unit): - if (unit == self.unit or not unit): + if unit == self.unit or not unit: return self new_value = self.unit.convert_value_to(self.value, unit) return TaggedValue(new_value, unit) @@ -194,9 +187,6 @@ def get_unit(self): return self.unit -TaggedValue = TaggedValueMeta('TaggedValue', (_TaggedValue, ), {}) - - class BasicUnit(object): def __init__(self, name, fullname=None): self.name = name diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index e2610703489d..15ba96030a89 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -2,9 +2,10 @@ unicode_literals) import six -from six.moves import reduce, xrange, zip, zip_longest +from six.moves import xrange, zip, zip_longest from collections import Sized +import functools import itertools import math import warnings @@ -16,14 +17,12 @@ from matplotlib import _preprocess_data import matplotlib.cbook as cbook -from matplotlib.cbook import ( - mplDeprecation, STEP_LOOKUP_MAP, iterable, safe_first_element) import matplotlib.collections as mcoll import matplotlib.colors as mcolors import matplotlib.contour as mcontour import matplotlib.category as _ # <-registers a category unit converter import matplotlib.dates as _ # <-registers a date unit converter -from matplotlib import docstring +import matplotlib.docstring as docstring import matplotlib.image as mimage import matplotlib.legend as mlegend import matplotlib.lines as mlines @@ -39,9 +38,10 @@ import matplotlib.ticker as mticker import matplotlib.transforms as mtransforms import matplotlib.tri as mtri +from matplotlib.cbook import ( + _backports, mplDeprecation, STEP_LOOKUP_MAP, iterable, safe_first_element) from matplotlib.container import BarContainer, ErrorbarContainer, StemContainer -from matplotlib.axes._base import _AxesBase -from matplotlib.axes._base import _process_plot_format +from matplotlib.axes._base import _AxesBase, _process_plot_format rcParams = matplotlib.rcParams @@ -2002,20 +2002,11 @@ def bar(self, left, height, width=0.8, bottom=None, **kwargs): label = kwargs.pop('label', '') tick_labels = kwargs.pop('tick_label', None) - def make_iterable(x): - if not iterable(x): - return [x] - else: - return x - - # make them safe to take len() of _left = left - left = make_iterable(left) - height = make_iterable(height) - width = make_iterable(width) _bottom = bottom - bottom = make_iterable(bottom) - linewidth = make_iterable(linewidth) + left, height, width, bottom = np.broadcast_arrays( + # Make args iterable too. + np.atleast_1d(left), height, width, bottom) adjust_ylim = False adjust_xlim = False @@ -2027,11 +2018,7 @@ def make_iterable(x): if _bottom is None: if self.get_yscale() == 'log': adjust_ylim = True - bottom = [0] - - nbars = len(left) - if len(bottom) == 1: - bottom *= nbars + bottom = np.zeros_like(bottom) tick_label_axis = self.xaxis tick_label_position = left @@ -2043,54 +2030,23 @@ def make_iterable(x): if _left is None: if self.get_xscale() == 'log': adjust_xlim = True - left = [0] - - nbars = len(bottom) - if len(left) == 1: - left *= nbars + left = np.zeros_like(left) tick_label_axis = self.yaxis tick_label_position = bottom else: raise ValueError('invalid orientation: %s' % orientation) - if len(height) == 1: - height *= nbars - if len(width) == 1: - width *= nbars - if len(linewidth) < nbars: - linewidth *= nbars - - color = list(mcolors.to_rgba_array(color)) - if len(color) == 0: # until to_rgba_array is changed - color = [[0, 0, 0, 0]] - if len(color) < nbars: - color *= nbars - + linewidth = itertools.cycle(np.atleast_1d(linewidth)) + color = itertools.chain(itertools.cycle(mcolors.to_rgba_array(color)), + # Fallback if color == "none". + itertools.repeat([0, 0, 0, 0])) if edgecolor is None: - edgecolor = [None] * nbars + edgecolor = itertools.repeat(None) else: - edgecolor = list(mcolors.to_rgba_array(edgecolor)) - if len(edgecolor) == 0: # until to_rgba_array is changed - edgecolor = [[0, 0, 0, 0]] - if len(edgecolor) < nbars: - edgecolor *= nbars - - # input validation - if len(left) != nbars: - raise ValueError("incompatible sizes: argument 'left' must " - "be length %d or scalar" % nbars) - if len(height) != nbars: - raise ValueError("incompatible sizes: argument 'height' " - "must be length %d or scalar" % nbars) - if len(width) != nbars: - raise ValueError("incompatible sizes: argument 'width' " - "must be length %d or scalar" % nbars) - if len(bottom) != nbars: - raise ValueError("incompatible sizes: argument 'bottom' " - "must be length %d or scalar" % nbars) - - patches = [] + edgecolor = itertools.chain(mcolors.to_rgba_array(edgecolor), + # Fallback if edgecolor == "none". + itertools.repeat([0, 0, 0, 0])) # lets do some conversions now since some types cannot be # subtracted uniformly @@ -2108,13 +2064,14 @@ def make_iterable(x): if align == 'center': if orientation == 'vertical': - left = [l - w / 2. for l, w in zip(left, width)] + left = left - width / 2 elif orientation == 'horizontal': - bottom = [b - h / 2. for b, h in zip(bottom, height)] + bottom = bottom - height / 2 elif align != 'edge': raise ValueError('invalid alignment: %s' % align) + patches = [] args = zip(left, bottom, width, height, color, edgecolor, linewidth) for l, b, w, h, c, e, lw in args: r = mpatches.Rectangle( @@ -2179,15 +2136,7 @@ def make_iterable(x): self.add_container(bar_container) if tick_labels is not None: - tick_labels = make_iterable(tick_labels) - if isinstance(tick_labels, six.string_types): - tick_labels = [tick_labels] - if len(tick_labels) == 1: - tick_labels *= nbars - if len(tick_labels) != nbars: - raise ValueError("incompatible sizes: argument 'tick_label' " - "must be length %d or string" % nbars) - + tick_labels = _backports.broadcast_to(tick_labels, len(patches)) tick_label_axis.set_ticks(tick_label_position) tick_label_axis.set_ticklabels(tick_labels) @@ -2613,7 +2562,7 @@ def get_next_color(): for frac, label, expl in zip(x, labels, explode): x, y = center theta2 = (theta1 + frac) if counterclock else (theta1 - frac) - thetam = 2 * math.pi * 0.5 * (theta1 + theta2) + thetam = 2 * np.pi * 0.5 * (theta1 + theta2) x += expl * math.cos(thetam) y += expl * math.sin(thetam) @@ -4782,22 +4731,12 @@ def fill_between(self, x, y1, y2=0, where=None, interpolate=False, raise ValueError('Input passed into argument "%r"' % name + 'is not 1-dimensional.') - if y1.ndim == 0: - y1 = np.ones_like(x) * y1 - if y2.ndim == 0: - y2 = np.ones_like(x) * y2 - if where is None: - where = np.ones(len(x), bool) - else: - where = np.asarray(where, bool) - - if not (x.shape == y1.shape == y2.shape == where.shape): - raise ValueError("Argument dimensions are incompatible") + where = True + where = where & ~functools.reduce(np.logical_or, + map(np.ma.getmask, [x, y1, y2])) - mask = reduce(ma.mask_or, [ma.getmask(a) for a in (x, y1, y2)]) - if mask is not ma.nomask: - where &= ~mask + x, y1, y2 = np.broadcast_arrays(np.atleast_1d(x), y1, y2) polys = [] for ind0, ind1 in mlab.contiguous_regions(where): @@ -4943,22 +4882,12 @@ def fill_betweenx(self, y, x1, x2=0, where=None, raise ValueError('Input passed into argument "%r"' % name + 'is not 1-dimensional.') - if x1.ndim == 0: - x1 = np.ones_like(y) * x1 - if x2.ndim == 0: - x2 = np.ones_like(y) * x2 - if where is None: - where = np.ones(len(y), bool) - else: - where = np.asarray(where, bool) - - if not (y.shape == x1.shape == x2.shape == where.shape): - raise ValueError("Argument dimensions are incompatible") + where = True + where = where & ~functools.reduce(np.logical_or, + map(np.ma.getmask, [y, x1, x2])) - mask = reduce(ma.mask_or, [ma.getmask(a) for a in (y, x1, x2)]) - if mask is not ma.nomask: - where &= ~mask + y, x1, x2 = np.broadcast_arrays(np.atleast_1d(y), x1, x2) polys = [] for ind0, ind1 in mlab.contiguous_regions(where): @@ -6584,7 +6513,6 @@ def psd(self, x, NFFT=None, Fs=None, Fc=None, detrend=None, if logi == 0: logi = .1 step = 10 * logi - #print vmin, vmax, step, intv, math.floor(vmin), math.ceil(vmax)+1 ticks = np.arange(math.floor(vmin), math.ceil(vmax) + 1, step) self.set_yticks(ticks) diff --git a/lib/matplotlib/backends/backend_agg.py b/lib/matplotlib/backends/backend_agg.py index b8b0eca92b0c..7e88d4064e5c 100644 --- a/lib/matplotlib/backends/backend_agg.py +++ b/lib/matplotlib/backends/backend_agg.py @@ -190,7 +190,8 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None): flags = get_hinting_flag() font = self._get_agg_font(prop) - if font is None: return None + if font is None: + return None if len(s) == 1 and ord(s) > 127: font.load_char(ord(s), flags=flags) else: diff --git a/lib/matplotlib/backends/backend_qt5.py b/lib/matplotlib/backends/backend_qt5.py index 9b924ce8ecb1..aae0da3e501e 100644 --- a/lib/matplotlib/backends/backend_qt5.py +++ b/lib/matplotlib/backends/backend_qt5.py @@ -648,8 +648,8 @@ def edit_parameters(self): QtWidgets.QMessageBox.warning( self.parent, "Error", "There are no axes to edit.") return - if len(allaxes) == 1: - axes = allaxes[0] + elif len(allaxes) == 1: + axes, = allaxes else: titles = [] for axes in allaxes: diff --git a/lib/matplotlib/backends/backend_wx.py b/lib/matplotlib/backends/backend_wx.py index f7df0707e637..2ad0106ce64c 100644 --- a/lib/matplotlib/backends/backend_wx.py +++ b/lib/matplotlib/backends/backend_wx.py @@ -316,7 +316,7 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None): if angle == 0.0: gfx_ctx.DrawText(s, x, y) else: - rads = angle / 180.0 * math.pi + rads = math.radians(angle) xo = h * math.sin(rads) yo = h * math.cos(rads) gfx_ctx.DrawRotatedText(s, x - xo, y - yo, rads) diff --git a/lib/matplotlib/cbook/__init__.py b/lib/matplotlib/cbook/__init__.py index 838081e33f66..f93f07beca97 100644 --- a/lib/matplotlib/cbook/__init__.py +++ b/lib/matplotlib/cbook/__init__.py @@ -11,7 +11,6 @@ import six from six.moves import xrange, zip -from itertools import repeat import collections import datetime import errno @@ -19,6 +18,7 @@ import glob import gzip import io +from itertools import repeat import locale import numbers import os @@ -1628,7 +1628,7 @@ def delete_masked_points(*args): except: # Fixme: put in tuple of possible exceptions? pass if len(masks): - mask = functools.reduce(np.logical_and, masks) + mask = np.logical_and.reduce(masks) igood = mask.nonzero()[0] if len(igood) < nrecs: for i, x in enumerate(margs): @@ -1993,7 +1993,7 @@ def _reshape_2D(X, name): *name* is used to generate the error message for invalid inputs. """ # Iterate over columns for ndarrays, over rows otherwise. - X = X.T if isinstance(X, np.ndarray) else np.asarray(X) + X = np.atleast_1d(X.T if isinstance(X, np.ndarray) else np.asarray(X)) if X.ndim == 1 and X.dtype.type != np.object_: # 1D array of scalars: directly return it. return [X] diff --git a/lib/matplotlib/colors.py b/lib/matplotlib/colors.py index 4cef8be06b69..8a35c6617bef 100644 --- a/lib/matplotlib/colors.py +++ b/lib/matplotlib/colors.py @@ -58,10 +58,12 @@ from __future__ import (absolute_import, division, print_function, unicode_literals) + import six from six.moves import zip from collections import Sized +import itertools import re import warnings @@ -793,25 +795,23 @@ def __init__(self, colors, name='from_list', N=None): the list will be extended by repetition. """ - self.colors = colors self.monochrome = False # True only if all colors in map are # identical; needed for contouring. if N is None: - N = len(self.colors) + self.colors = colors + N = len(colors) else: - if isinstance(self.colors, six.string_types): - self.colors = [self.colors] * N + if isinstance(colors, six.string_types): + self.colors = [colors] * N self.monochrome = True - elif cbook.iterable(self.colors): - self.colors = list(self.colors) # in case it was a tuple - if len(self.colors) == 1: + elif cbook.iterable(colors): + if len(colors) == 1: self.monochrome = True - if len(self.colors) < N: - self.colors = list(self.colors) * N - del(self.colors[N:]) + self.colors = list( + itertools.islice(itertools.cycle(colors), N)) else: try: - gray = float(self.colors) + gray = float(colors) except TypeError: pass else: diff --git a/lib/matplotlib/gridspec.py b/lib/matplotlib/gridspec.py index c9779cf23dd1..999dbd8c2029 100644 --- a/lib/matplotlib/gridspec.py +++ b/lib/matplotlib/gridspec.py @@ -98,28 +98,24 @@ def get_grid_positions(self, fig): # calculate accumulated heights of columns cellH = totHeight / (nrows + hspace*(nrows-1)) sepH = hspace * cellH - if self._row_height_ratios is not None: netHeight = cellH * nrows tr = float(sum(self._row_height_ratios)) cellHeights = [netHeight * r / tr for r in self._row_height_ratios] else: cellHeights = [cellH] * nrows - sepHeights = [0] + ([sepH] * (nrows-1)) cellHs = np.cumsum(np.column_stack([sepHeights, cellHeights]).flat) # calculate accumulated widths of rows cellW = totWidth/(ncols + wspace*(ncols-1)) sepW = wspace*cellW - if self._col_width_ratios is not None: netWidth = cellW * ncols tr = float(sum(self._col_width_ratios)) cellWidths = [netWidth*r/tr for r in self._col_width_ratios] else: cellWidths = [cellW] * ncols - sepWidths = [0] + ([sepW] * (ncols-1)) cellWs = np.cumsum(np.column_stack([sepWidths, cellWidths]).flat) diff --git a/lib/matplotlib/legend.py b/lib/matplotlib/legend.py index 9d3a9ab46775..b9afbb6f3e7a 100644 --- a/lib/matplotlib/legend.py +++ b/lib/matplotlib/legend.py @@ -294,7 +294,7 @@ def __init__(self, parent, handles, labels, self._scatteryoffsets = np.array([3. / 8., 4. / 8., 2.5 / 8.]) else: self._scatteryoffsets = np.asarray(scatteryoffsets) - reps = int(self.scatterpoints / len(self._scatteryoffsets)) + 1 + reps = self.scatterpoints // len(self._scatteryoffsets) + 1 self._scatteryoffsets = np.tile(self._scatteryoffsets, reps)[:self.scatterpoints] diff --git a/lib/matplotlib/lines.py b/lib/matplotlib/lines.py index 256e59c2eb2e..929082206049 100644 --- a/lib/matplotlib/lines.py +++ b/lib/matplotlib/lines.py @@ -665,20 +665,8 @@ def recache(self, always=False): else: y = self._y - if len(x) == 1 and len(y) > 1: - x = x * np.ones(y.shape, float) - if len(y) == 1 and len(x) > 1: - y = y * np.ones(x.shape, float) - - if len(x) != len(y): - raise RuntimeError('xdata and ydata must be the same length') - - self._xy = np.empty((len(x), 2), dtype=float) - self._xy[:, 0] = x - self._xy[:, 1] = y - - self._x = self._xy[:, 0] # just a view - self._y = self._xy[:, 1] # just a view + self._xy = np.column_stack(np.broadcast_arrays(x, y)).astype(float) + self._x, self._y = self._xy.T # views self._subslice = False if (self.axes and len(x) > 1000 and self._is_sorted(x) and diff --git a/lib/matplotlib/offsetbox.py b/lib/matplotlib/offsetbox.py index e15fcad221b7..d62a509eb3dc 100644 --- a/lib/matplotlib/offsetbox.py +++ b/lib/matplotlib/offsetbox.py @@ -71,22 +71,19 @@ def _get_packed_offsets(wd_list, total, sep, mode="fixed"): # d_list is currently not used. if mode == "fixed": - offsets_ = np.add.accumulate([0] + [w + sep for w in w_list]) + offsets_ = np.cumsum([0] + [w + sep for w in w_list]) offsets = offsets_[:-1] - if total is None: total = offsets_[-1] - sep - return total, offsets elif mode == "expand": if len(w_list) > 1: sep = (total - sum(w_list)) / (len(w_list) - 1.) else: - sep = 0. - offsets_ = np.add.accumulate([0] + [w + sep for w in w_list]) + sep = 0 + offsets_ = np.cumsum([0] + [w + sep for w in w_list]) offsets = offsets_[:-1] - return total, offsets elif mode == "equal": @@ -94,10 +91,8 @@ def _get_packed_offsets(wd_list, total, sep, mode="fixed"): if total is None: total = (maxh + sep) * len(w_list) else: - sep = float(total) / (len(w_list)) - maxh - - offsets = np.array([(maxh + sep) * i for i in range(len(w_list))]) - + sep = total / len(w_list) - maxh + offsets = (maxh + sep) * np.arange(len(w_list)) return total, offsets else: diff --git a/lib/matplotlib/patches.py b/lib/matplotlib/patches.py index 29f11519d70d..37c92f119359 100644 --- a/lib/matplotlib/patches.py +++ b/lib/matplotlib/patches.py @@ -1389,10 +1389,10 @@ def getpoints(self, x1, y1, x2, y2, k): b = -2 * y2 c = y2 ** 2. - k ** 2. * pm ** 2. / (1. + pm ** 2.) - y3a = (-b + math.sqrt(b ** 2. - 4 * a * c)) / (2. * a) + y3a = (-b + math.sqrt(b ** 2 - 4 * a * c)) / (2 * a) x3a = (y3a - y2) / pm + x2 - y3b = (-b - math.sqrt(b ** 2. - 4 * a * c)) / (2. * a) + y3b = (-b - math.sqrt(b ** 2 - 4 * a * c)) / (2 * a) x3b = (y3b - y2) / pm + x2 return x3a, y3a, x3b, y3b @@ -1651,8 +1651,7 @@ def theta_stretch(theta, scale): theta2 = theta_stretch(self.theta2, width / height) # Get width and height in pixels - width, height = self.get_transform().transform_point( - (width, height)) + width, height = self.get_transform().transform_point((width, height)) inv_error = (1.0 / 1.89818e-6) * 0.5 if width < inv_error and height < inv_error: self._path = Path.arc(theta1, theta2) @@ -2883,10 +2882,10 @@ def connect(self, posA, posB): x1, y1 = posA x2, y2 = posB - cosA, sinA = (math.cos(self.angleA / 180. * math.pi), - math.sin(self.angleA / 180. * math.pi)) - cosB, sinB = (math.cos(self.angleB / 180. * math.pi), - math.sin(self.angleB / 180. * math.pi)) + cosA = math.cos(math.radians(self.angleA)) + sinA = math.sin(math.radians(self.angleA)) + cosB = math.cos(math.radians(self.angleB)) + sinB = math.sin(math.radians(self.angleB)) cx, cy = get_intersection(x1, y1, cosA, sinA, x2, y2, cosB, sinB) @@ -2928,10 +2927,10 @@ def connect(self, posA, posB): x1, y1 = posA x2, y2 = posB - cosA, sinA = (math.cos(self.angleA / 180. * math.pi), - math.sin(self.angleA / 180. * math.pi)) - cosB, sinB = (math.cos(self.angleB / 180. * math.pi), - math.sin(self.angleB / 180. * math.pi)) + cosA = math.cos(math.radians(self.angleA)) + sinA = math.sin(math.radians(self.angleA)) + cosB = math.cos(math.radians(self.angleB)) + sinB = math.sin(math.radians(self.angleB)) cx, cy = get_intersection(x1, y1, cosA, sinA, x2, y2, cosB, sinB) @@ -3004,8 +3003,8 @@ def connect(self, posA, posB): codes = [Path.MOVETO] if self.armA: - cosA = math.cos(self.angleA / 180. * math.pi) - sinA = math.sin(self.angleA / 180. * math.pi) + cosA = math.cos(math.radians(self.angleA)) + sinA = math.sin(math.radians(self.angleA)) # x_armA, y_armB d = self.armA - self.rad rounded.append((x1 + d * cosA, y1 + d * sinA)) @@ -3013,8 +3012,8 @@ def connect(self, posA, posB): rounded.append((x1 + d * cosA, y1 + d * sinA)) if self.armB: - cosB = math.cos(self.angleB / 180. * math.pi) - sinB = math.sin(self.angleB / 180. * math.pi) + cosB = math.cos(math.radians(self.angleB)) + sinB = math.sin(math.radians(self.angleB)) x_armB, y_armB = x2 + self.armB * cosB, y2 + self.armB * sinB if rounded: @@ -3099,14 +3098,11 @@ def connect(self, posA, posB): armA, armB = self.armA, self.armB if self.angle is not None: - theta0 = self.angle / 180. * math.pi + theta0 = np.deg2rad(self.angle) dtheta = theta1 - theta0 - dl = dd * math.sin(dtheta) dL = dd * math.cos(dtheta) - x2, y2 = x1 + dL * math.cos(theta0), y1 + dL * math.sin(theta0) - armB = armB - dl # update @@ -3354,8 +3350,8 @@ def _get_arrow_wedge(self, x0, y0, x1, y1, def transmute(self, path, mutation_size, linewidth): - head_length, head_width = self.head_length * mutation_size, \ - self.head_width * mutation_size + head_length = self.head_length * mutation_size + head_width = self.head_width * mutation_size head_dist = math.sqrt(head_length ** 2 + head_width ** 2) cos_t, sin_t = head_length / head_dist, head_width / head_dist @@ -3364,8 +3360,7 @@ def transmute(self, path, mutation_size, linewidth): x1, y1 = path.vertices[1] # If there is no room for an arrow and a line, then skip the arrow - has_begin_arrow = (self.beginarrow and - not ((x0 == x1) and (y0 == y1))) + has_begin_arrow = self.beginarrow and not (x0 == x1 and y0 == y1) if has_begin_arrow: verticesA, codesA, ddxA, ddyA = \ self._get_arrow_wedge(x1, y1, x0, y0, diff --git a/lib/matplotlib/path.py b/lib/matplotlib/path.py index fcaf191dc04b..28612925de84 100644 --- a/lib/matplotlib/path.py +++ b/lib/matplotlib/path.py @@ -758,7 +758,7 @@ def circle(cls, center=(0., 0.), radius=1., readonly=False): """ MAGIC = 0.2652031 SQRTHALF = np.sqrt(0.5) - MAGIC45 = np.sqrt((MAGIC*MAGIC) / 2.0) + MAGIC45 = SQRTHALF * MAGIC vertices = np.array([[0.0, -1.0], @@ -818,7 +818,7 @@ def unit_circle_righthalf(cls): if cls._unit_circle_righthalf is None: MAGIC = 0.2652031 SQRTHALF = np.sqrt(0.5) - MAGIC45 = np.sqrt((MAGIC*MAGIC) / 2.0) + MAGIC45 = SQRTHALF * MAGIC vertices = np.array( [[0.0, -1.0], diff --git a/lib/matplotlib/projections/geo.py b/lib/matplotlib/projections/geo.py index 00071e6d05dc..926a22fa5de5 100644 --- a/lib/matplotlib/projections/geo.py +++ b/lib/matplotlib/projections/geo.py @@ -382,15 +382,11 @@ def __init__(self, resolution): self._resolution = resolution def transform_non_affine(self, xy): - x = xy[:, 0:1] - y = xy[:, 1:2] - - quarter_x = 0.25 * x - half_y = 0.5 * y - z = np.sqrt(1.0 - quarter_x*quarter_x - half_y*half_y) - longitude = 2 * np.arctan((z*x) / (2.0 * (2.0*z*z - 1.0))) + x, y = xy.T + z = np.sqrt(1 - (x / 4) ** 2 - (y / 2) ** 2) + longitude = 2 * np.arctan((z * x) / (2 * (2 * z ** 2 - 1))) latitude = np.arcsin(y*z) - return np.concatenate((longitude, latitude), 1) + return np.column_stack([longitude, latitude]) transform_non_affine.__doc__ = Transform.transform_non_affine.__doc__ def inverted(self): diff --git a/lib/matplotlib/projections/polar.py b/lib/matplotlib/projections/polar.py index e059c1ee375a..5955ffb5fb1e 100644 --- a/lib/matplotlib/projections/polar.py +++ b/lib/matplotlib/projections/polar.py @@ -1,7 +1,7 @@ from __future__ import (absolute_import, division, print_function, unicode_literals) -import collections +from collections import OrderedDict import numpy as np @@ -646,7 +646,7 @@ def _gen_axes_patch(self): return mpatches.Wedge((0.5, 0.5), 0.5, 0.0, 360.0) def _gen_axes_spines(self): - spines = collections.OrderedDict([ + spines = OrderedDict([ ('polar', mspines.Spine.arc_spine(self, 'top', (0.5, 0.5), 0.5, 0.0, 360.0)), ('start', mspines.Spine.linear_spine(self, 'left')), diff --git a/lib/matplotlib/stackplot.py b/lib/matplotlib/stackplot.py index 8b34f7697711..2c0b7e6d1b82 100644 --- a/lib/matplotlib/stackplot.py +++ b/lib/matplotlib/stackplot.py @@ -55,10 +55,7 @@ def stackplot(axes, x, *args, **kwargs): element in the stacked area plot. """ - if len(args) == 1: - y = np.atleast_2d(*args) - elif len(args) > 1: - y = np.row_stack(args) + y = np.row_stack(args) labels = iter(kwargs.pop('labels', [])) diff --git a/lib/matplotlib/tests/baseline_images/test_axes/fill_between_interpolate.pdf b/lib/matplotlib/tests/baseline_images/test_axes/fill_between_interpolate.pdf index 952ed88f4d8d..eeb8969fa702 100644 Binary files a/lib/matplotlib/tests/baseline_images/test_axes/fill_between_interpolate.pdf and b/lib/matplotlib/tests/baseline_images/test_axes/fill_between_interpolate.pdf differ diff --git a/lib/matplotlib/tests/baseline_images/test_axes/fill_between_interpolate.png b/lib/matplotlib/tests/baseline_images/test_axes/fill_between_interpolate.png index 7d705b038b43..59c32a9084d7 100644 Binary files a/lib/matplotlib/tests/baseline_images/test_axes/fill_between_interpolate.png and b/lib/matplotlib/tests/baseline_images/test_axes/fill_between_interpolate.png differ diff --git a/lib/matplotlib/tests/baseline_images/test_axes/fill_between_interpolate.svg b/lib/matplotlib/tests/baseline_images/test_axes/fill_between_interpolate.svg index cb7a2e09ee12..35a003c97c21 100644 --- a/lib/matplotlib/tests/baseline_images/test_axes/fill_between_interpolate.svg +++ b/lib/matplotlib/tests/baseline_images/test_axes/fill_between_interpolate.svg @@ -27,7 +27,7 @@ z " style="fill:#ffffff;"/> - - + - + - + +" style="fill:url(#hd3108e6b65);stroke:#000000;"/> - - - - - - - +" id="me5bf4c00e3" style="stroke:#000000;stroke-width:0.5;"/> - + +" id="m074e64995f" style="stroke:#000000;stroke-width:0.5;"/> - + - + - + - + - + - + - + - + - + @@ -572,92 +572,92 @@ L 0 4 +" id="m414a7409eb" style="stroke:#000000;stroke-width:0.5;"/> - + +" id="ma2b7fc1d98" style="stroke:#000000;stroke-width:0.5;"/> - + - + - + - + - + - + - + - + - + - + - + - + - + @@ -673,7 +673,7 @@ z " style="fill:#ffffff;"/> - - - - - - - - - - - - - - - + - + - + - + - + - + - + - + - + - + @@ -1153,72 +1153,72 @@ L 518.4 231.709091 - + - + - + - + - + - + - + - + - + - + - + - + @@ -1226,15 +1226,15 @@ L 518.4 231.709091 - - + + - - + + - +