diff --git a/examples/api/font_file.py b/examples/api/font_file.py index 007189151a7a..af035bf7e95f 100644 --- a/examples/api/font_file.py +++ b/examples/api/font_file.py @@ -15,7 +15,8 @@ """ import os -from matplotlib import font_manager as fm, pyplot as plt, rcParams +from matplotlib import font_manager as fm, rcParams +import matplotlib.pyplot as plt fig, ax = plt.subplots() diff --git a/examples/api/power_norm.py b/examples/api/power_norm.py index 08e03297aed8..491792c1a4b1 100644 --- a/examples/api/power_norm.py +++ b/examples/api/power_norm.py @@ -7,7 +7,7 @@ """ -from matplotlib import pyplot as plt +import matplotlib.pyplot as plt import matplotlib.colors as mcolors import numpy as np from numpy.random import multivariate_normal diff --git a/examples/axes_grid1/demo_colorbar_with_axes_divider.py b/examples/axes_grid1/demo_colorbar_with_axes_divider.py index f077c5b40b96..1760be62ef22 100644 --- a/examples/axes_grid1/demo_colorbar_with_axes_divider.py +++ b/examples/axes_grid1/demo_colorbar_with_axes_divider.py @@ -4,27 +4,23 @@ =============================== """ + import matplotlib.pyplot as plt from mpl_toolkits.axes_grid1.axes_divider import make_axes_locatable - from mpl_toolkits.axes_grid1.colorbar import colorbar -# from matplotlib.pyplot import colorbar -fig = plt.figure(1, figsize=(6, 3)) +fig, (ax1, ax2) = plt.subplots(1, 2) fig.subplots_adjust(wspace=0.5) -ax1 = fig.add_subplot(121) im1 = ax1.imshow([[1, 2], [3, 4]]) - ax1_divider = make_axes_locatable(ax1) cax1 = ax1_divider.append_axes("right", size="7%", pad="2%") cb1 = colorbar(im1, cax=cax1) -ax2 = fig.add_subplot(122) im2 = ax2.imshow([[1, 2], [3, 4]]) - ax2_divider = make_axes_locatable(ax2) cax2 = ax2_divider.append_axes("top", size="7%", pad="2%") cb2 = colorbar(im2, cax=cax2, orientation="horizontal") cax2.xaxis.set_ticks_position("top") + plt.show() diff --git a/examples/event_handling/lasso_demo.py b/examples/event_handling/lasso_demo.py index 24f13f43c4d2..df3a88ce672b 100644 --- a/examples/event_handling/lasso_demo.py +++ b/examples/event_handling/lasso_demo.py @@ -10,13 +10,12 @@ This is currently a proof-of-concept implementation (though it is usable as is). There will be some refinement of the API. """ -from matplotlib.widgets import Lasso -from matplotlib.collections import RegularPolyCollection -from matplotlib import colors as mcolors, path +from matplotlib import colors as mcolors, path +from matplotlib.collections import RegularPolyCollection import matplotlib.pyplot as plt -from numpy import nonzero -from numpy.random import rand +from matplotlib.widgets import Lasso +import numpy as np class Datum(object): @@ -77,9 +76,12 @@ def onpress(self, event): # acquire a lock on the widget drawing self.canvas.widgetlock(self.lasso) + if __name__ == '__main__': - data = [Datum(*xy) for xy in rand(100, 2)] + np.random.seed(19680801) + + data = [Datum(*xy) for xy in np.random.rand(100, 2)] ax = plt.axes(xlim=(0, 1), ylim=(0, 1), autoscale_on=False) ax.set_title('Lasso points using left mouse button') diff --git a/examples/event_handling/pick_event_demo2.py b/examples/event_handling/pick_event_demo2.py index 48ac59e0ae26..72cd4d6f4719 100644 --- a/examples/event_handling/pick_event_demo2.py +++ b/examples/event_handling/pick_event_demo2.py @@ -29,11 +29,10 @@ def onpick(event): if not N: return True - figi = plt.figure() - for subplotnum, dataind in enumerate(event.ind): - ax = figi.add_subplot(N, 1, subplotnum + 1) + figi, axs = plt.subplots(N, squeeze=False) + for ax, dataind in zip(axs.flat, event.ind): ax.plot(X[dataind]) - ax.text(0.05, 0.9, 'mu=%1.3f\nsigma=%1.3f' % (xs[dataind], ys[dataind]), + ax.text(.05, .9, 'mu=%1.3f\nsigma=%1.3f' % (xs[dataind], ys[dataind]), transform=ax.transAxes, va='top') ax.set_ylim(-0.5, 1.5) figi.show() diff --git a/examples/event_handling/zoom_window.py b/examples/event_handling/zoom_window.py index b84afeb67daf..c2cc1cce5561 100644 --- a/examples/event_handling/zoom_window.py +++ b/examples/event_handling/zoom_window.py @@ -6,27 +6,27 @@ This example shows how to connect events in one window, for example, a mouse press, to another figure window. -If you click on a point in the first window, the z and y limits of the -second will be adjusted so that the center of the zoom in the second -window will be the x,y coordinates of the clicked point. +If you click on a point in the first window, the z and y limits of the second +will be adjusted so that the center of the zoom in the second window will be +the x,y coordinates of the clicked point. -Note the diameter of the circles in the scatter are defined in -points**2, so their size is independent of the zoom +Note the diameter of the circles in the scatter are defined in points**2, so +their size is independent of the zoom. """ -from matplotlib.pyplot import figure, show + +import matplotlib.pyplot as plt import numpy as np -figsrc = figure() -figzoom = figure() - -axsrc = figsrc.add_subplot(111, xlim=(0, 1), ylim=(0, 1), autoscale_on=False) -axzoom = figzoom.add_subplot(111, xlim=(0.45, 0.55), ylim=(0.4, .6), - autoscale_on=False) -axsrc.set_title('Click to zoom') -axzoom.set_title('zoom window') + +figsrc, axsrc = plt.subplots() +figzoom, axzoom = plt.subplots() +axsrc.set(xlim=(0, 1), ylim=(0, 1), autoscale_on=False, + title='Click to zoom') +axzoom.set(xlim=(0.45, 0.55), ylim=(0.4, 0.6), autoscale_on=False, + title='Zoom window') + x, y, s, c = np.random.rand(4, 200) s *= 200 - axsrc.scatter(x, y, s, c) axzoom.scatter(x, y, s, c) @@ -40,4 +40,4 @@ def onpress(event): figzoom.canvas.draw() figsrc.canvas.mpl_connect('button_press_event', onpress) -show() +plt.show() diff --git a/examples/images_contours_and_fields/multi_image.py b/examples/images_contours_and_fields/multi_image.py index 43d9d0b6b6f2..6f6b3565b3bf 100644 --- a/examples/images_contours_and_fields/multi_image.py +++ b/examples/images_contours_and_fields/multi_image.py @@ -6,7 +6,8 @@ Make a set of images with a single colormap, norm, and colorbar. """ -from matplotlib import colors, pyplot as plt +from matplotlib import colors +import matplotlib.pyplot as plt import numpy as np np.random.seed(19680801) diff --git a/examples/lines_bars_and_markers/eventplot_demo.py b/examples/lines_bars_and_markers/eventplot_demo.py index f11a6b3148f4..32e74c8ffe89 100644 --- a/examples/lines_bars_and_markers/eventplot_demo.py +++ b/examples/lines_bars_and_markers/eventplot_demo.py @@ -32,18 +32,15 @@ lineoffsets1 = np.array([-15, -3, 1, 1.5, 6, 10]) linelengths1 = [5, 2, 1, 1, 3, 1.5] -fig = plt.figure() +fig, axs = plt.subplots(2, 2) # create a horizontal plot -ax1 = fig.add_subplot(221) -ax1.eventplot(data1, colors=colors1, lineoffsets=lineoffsets1, - linelengths=linelengths1) - +axs[0, 0].eventplot(data1, colors=colors1, lineoffsets=lineoffsets1, + linelengths=linelengths1) # create a vertical plot -ax2 = fig.add_subplot(223) -ax2.eventplot(data1, colors=colors1, lineoffsets=lineoffsets1, - linelengths=linelengths1, orientation='vertical') +axs[1, 0].eventplot(data1, colors=colors1, lineoffsets=lineoffsets1, + linelengths=linelengths1, orientation='vertical') # create another set of random data. # the gamma distribution is only used fo aesthetic purposes @@ -57,14 +54,12 @@ linelengths2 = 1 # create a horizontal plot -ax1 = fig.add_subplot(222) -ax1.eventplot(data2, colors=colors2, lineoffsets=lineoffsets2, - linelengths=linelengths2) +axs[0, 1].eventplot(data2, colors=colors2, lineoffsets=lineoffsets2, + linelengths=linelengths2) # create a vertical plot -ax2 = fig.add_subplot(224) -ax2.eventplot(data2, colors=colors2, lineoffsets=lineoffsets2, - linelengths=linelengths2, orientation='vertical') +axs[1, 1].eventplot(data2, colors=colors2, lineoffsets=lineoffsets2, + linelengths=linelengths2, orientation='vertical') plt.show() diff --git a/examples/lines_bars_and_markers/gradient_bar.py b/examples/lines_bars_and_markers/gradient_bar.py index 84320a0d4db2..eae4c44ab168 100644 --- a/examples/lines_bars_and_markers/gradient_bar.py +++ b/examples/lines_bars_and_markers/gradient_bar.py @@ -5,8 +5,9 @@ """ import matplotlib.pyplot as plt -from numpy import arange -from numpy.random import rand +import numpy as np + +np.random.seed(19680801) def gbar(ax, x, y, width=0.5, bottom=0): @@ -17,20 +18,19 @@ def gbar(ax, x, y, width=0.5, bottom=0): extent=(left, right, bottom, top), alpha=1) -fig = plt.figure() - xmin, xmax = xlim = 0, 10 ymin, ymax = ylim = 0, 1 -ax = fig.add_subplot(111, xlim=xlim, ylim=ylim, - autoscale_on=False) -X = [[.6, .6], [.7, .7]] +fig, ax = plt.subplots() +ax.set(xlim=xlim, ylim=ylim, autoscale_on=False) + +X = [[.6, .6], [.7, .7]] ax.imshow(X, interpolation='bicubic', cmap=plt.cm.copper, extent=(xmin, xmax, ymin, ymax), alpha=1) N = 10 -x = arange(N) + 0.25 -y = rand(N) +x = np.arange(N) + 0.25 +y = np.random.rand(N) gbar(ax, x, y, width=0.7) ax.set_aspect('auto') plt.show() diff --git a/examples/lines_bars_and_markers/interp_demo.py b/examples/lines_bars_and_markers/interp_demo.py index 40e8978854aa..4fcab49f4b94 100644 --- a/examples/lines_bars_and_markers/interp_demo.py +++ b/examples/lines_bars_and_markers/interp_demo.py @@ -5,13 +5,13 @@ """ import matplotlib.pyplot as plt -from numpy import pi, sin, linspace +import numpy as np from matplotlib.mlab import stineman_interp -x = linspace(0, 2*pi, 20) -y = sin(x) +x = np.linspace(0, 2*np.pi, 20) +y = np.sin(x) yp = None -xi = linspace(x[0], x[-1], 100) +xi = np.linspace(x[0], x[-1], 100) yi = stineman_interp(xi, x, y, yp) fig, ax = plt.subplots() diff --git a/examples/lines_bars_and_markers/scatter_symbol.py b/examples/lines_bars_and_markers/scatter_symbol.py index c9caaeb94339..bee25f03ddc7 100644 --- a/examples/lines_bars_and_markers/scatter_symbol.py +++ b/examples/lines_bars_and_markers/scatter_symbol.py @@ -4,7 +4,7 @@ ============== """ -from matplotlib import pyplot as plt +import matplotlib.pyplot as plt import numpy as np import matplotlib diff --git a/examples/lines_bars_and_markers/simple_plot.py b/examples/lines_bars_and_markers/simple_plot.py index 4aed2f40cb55..ab40ac15ae31 100644 --- a/examples/lines_bars_and_markers/simple_plot.py +++ b/examples/lines_bars_and_markers/simple_plot.py @@ -5,6 +5,7 @@ Create a simple plot. """ + import matplotlib.pyplot as plt import numpy as np @@ -13,7 +14,7 @@ s = 1 + np.sin(2 * np.pi * t) # Note that using plt.subplots below is equivalent to using -# fig = plt.figure and then ax = fig.add_subplot(111) +# fig = plt.figure() and then ax = fig.add_subplot(111) fig, ax = plt.subplots() ax.plot(t, s) diff --git a/examples/misc/pythonic_matplotlib.py b/examples/misc/pythonic_matplotlib.py index 07c6fa915a92..b04d931264f0 100644 --- a/examples/misc/pythonic_matplotlib.py +++ b/examples/misc/pythonic_matplotlib.py @@ -14,7 +14,6 @@ instances, managing the bounding boxes of the figure elements, creating and realizing GUI windows and embedding figures in them. - If you are an application developer and want to embed matplotlib in your application, follow the lead of examples/embedding_in_wx.py, examples/embedding_in_gtk.py or examples/embedding_in_tk.py. In this @@ -55,16 +54,14 @@ a.set_yticks([]) """ +import matplotlib.pyplot as plt +import numpy as np -from matplotlib.pyplot import figure, show -from numpy import arange, sin, pi - -t = arange(0.0, 1.0, 0.01) +t = np.arange(0.0, 1.0, 0.01) -fig = figure(1) +fig, (ax1, ax2) = plt.subplots(2) -ax1 = fig.add_subplot(211) -ax1.plot(t, sin(2*pi * t)) +ax1.plot(t, np.sin(2*np.pi * t)) ax1.grid(True) ax1.set_ylim((-2, 2)) ax1.set_ylabel('1 Hz') @@ -72,13 +69,11 @@ ax1.xaxis.set_tick_params(labelcolor='r') - -ax2 = fig.add_subplot(212) -ax2.plot(t, sin(2 * 2*pi * t)) +ax2.plot(t, np.sin(2 * 2*np.pi * t)) ax2.grid(True) ax2.set_ylim((-2, 2)) l = ax2.set_xlabel('Hi mom') l.set_color('g') l.set_fontsize('large') -show() +plt.show() diff --git a/examples/mplot3d/surface3d_radial.py b/examples/mplot3d/surface3d_radial.py index b5830c359b8c..9125624eca45 100644 --- a/examples/mplot3d/surface3d_radial.py +++ b/examples/mplot3d/surface3d_radial.py @@ -11,7 +11,7 @@ ''' from mpl_toolkits.mplot3d import Axes3D -from matplotlib import pyplot as plt +import matplotlib.pyplot as plt import numpy as np diff --git a/examples/pie_and_polar_charts/nested_pie.py b/examples/pie_and_polar_charts/nested_pie.py index 7dd77a1f531d..8f593d36397a 100644 --- a/examples/pie_and_polar_charts/nested_pie.py +++ b/examples/pie_and_polar_charts/nested_pie.py @@ -8,7 +8,7 @@ """ -from matplotlib import pyplot as plt +import matplotlib.pyplot as plt import numpy as np ############################################################################### diff --git a/examples/pie_and_polar_charts/polar_legend.py b/examples/pie_and_polar_charts/polar_legend.py index 5b87c2b8d3e8..4fe6b201090f 100644 --- a/examples/pie_and_polar_charts/polar_legend.py +++ b/examples/pie_and_polar_charts/polar_legend.py @@ -5,16 +5,17 @@ Demo of a legend on a polar-axis plot. """ + +import matplotlib.pyplot as plt import numpy as np -from matplotlib.pyplot import figure, show, rc # radar green, solid grid lines -rc('grid', color='#316931', linewidth=1, linestyle='-') -rc('xtick', labelsize=15) -rc('ytick', labelsize=15) +plt.rc('grid', color='#316931', linewidth=1, linestyle='-') +plt.rc('xtick', labelsize=15) +plt.rc('ytick', labelsize=15) # force square figure and square axes looks better for polar, IMO -fig = figure(figsize=(8, 8)) +fig = plt.figure(figsize=(8, 8)) ax = fig.add_axes([0.1, 0.1, 0.8, 0.8], projection='polar', facecolor='#d5de9c') @@ -24,4 +25,4 @@ ax.plot(0.5 * theta, r, color='blue', ls='--', lw=3, label='another line') ax.legend() -show() +plt.show() diff --git a/examples/pyplots/align_ylabels.py b/examples/pyplots/align_ylabels.py index b2eb0bdf6813..63558b0c8b45 100644 --- a/examples/pyplots/align_ylabels.py +++ b/examples/pyplots/align_ylabels.py @@ -9,35 +9,30 @@ box = dict(facecolor='yellow', pad=5, alpha=0.2) -fig = plt.figure() +fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2) fig.subplots_adjust(left=0.2, wspace=0.6) # Fixing random state for reproducibility np.random.seed(19680801) -ax1 = fig.add_subplot(221) ax1.plot(2000*np.random.rand(10)) ax1.set_title('ylabels not aligned') ax1.set_ylabel('misaligned 1', bbox=box) ax1.set_ylim(0, 2000) -ax3 = fig.add_subplot(223) + ax3.set_ylabel('misaligned 2',bbox=box) ax3.plot(np.random.rand(10)) - labelx = -0.3 # axes coords -ax2 = fig.add_subplot(222) ax2.set_title('ylabels aligned') ax2.plot(2000*np.random.rand(10)) ax2.set_ylabel('aligned 1', bbox=box) ax2.yaxis.set_label_coords(labelx, 0.5) ax2.set_ylim(0, 2000) -ax4 = fig.add_subplot(224) ax4.plot(np.random.rand(10)) ax4.set_ylabel('aligned 2', bbox=box) ax4.yaxis.set_label_coords(labelx, 0.5) - plt.show() diff --git a/examples/pyplots/dollar_ticks.py b/examples/pyplots/dollar_ticks.py index 5ab6f7948a91..2f8c864e977c 100644 --- a/examples/pyplots/dollar_ticks.py +++ b/examples/pyplots/dollar_ticks.py @@ -11,8 +11,7 @@ # Fixing random state for reproducibility np.random.seed(19680801) -fig = plt.figure() -ax = fig.add_subplot(111) +fig, ax = plt.subplots() ax.plot(100*np.random.rand(20)) formatter = ticker.FormatStrFormatter('$%1.2f') diff --git a/examples/recipes/common_date_problems.py b/examples/recipes/common_date_problems.py index cb9bde619195..5ef4fb64fc8d 100644 --- a/examples/recipes/common_date_problems.py +++ b/examples/recipes/common_date_problems.py @@ -55,9 +55,9 @@ # Matplotlib prefers datetime instead of np.datetime64. date = r.date.astype('O') -plt.figure() -plt.plot(date, r.close) -plt.title('Default date handling can cause overlapping labels') +fig, ax = plt.subplots() +ax.plot(date, r.close) +ax.set_title('Default date handling can cause overlapping labels') ############################################################################### # Another annoyance is that if you hover the mouse over the window and @@ -88,3 +88,5 @@ ############################################################################### # Now when you hover your mouse over the plotted data, you'll see date # format strings like 2004-12-01 in the toolbar. + +plt.show() diff --git a/examples/recipes/create_subplots.py b/examples/recipes/create_subplots.py index 1a177d3c9cbf..32ea893801ea 100644 --- a/examples/recipes/create_subplots.py +++ b/examples/recipes/create_subplots.py @@ -37,3 +37,5 @@ # new style method 2; use an axes array fig, axs = plt.subplots(2, 2, sharex=True, sharey=True) axs[0, 0].plot(x) + +plt.show() diff --git a/examples/recipes/fill_between_alpha.py b/examples/recipes/fill_between_alpha.py index 16216aedb17d..3a53841b33d7 100644 --- a/examples/recipes/fill_between_alpha.py +++ b/examples/recipes/fill_between_alpha.py @@ -134,3 +134,5 @@ # functions :meth:`~matplotlib.axes.Axes.axhspan` and # :meth:`~matplotlib.axes.Axes.axvspan` and example # :ref:`sphx_glr_gallery_subplots_axes_and_figures_axhspan_demo.py`. + +plt.show() diff --git a/examples/recipes/placing_text_boxes.py b/examples/recipes/placing_text_boxes.py index 2ab8986fdef6..882839c502b7 100644 --- a/examples/recipes/placing_text_boxes.py +++ b/examples/recipes/placing_text_boxes.py @@ -13,7 +13,7 @@ import numpy as np import matplotlib.pyplot as plt -np.random.seed(1234) +np.random.seed(19680801) fig, ax = plt.subplots() x = 30*np.random.randn(10000) @@ -29,3 +29,5 @@ # place a text box in upper left in axes coords ax.text(0.05, 0.95, textstr, transform=ax.transAxes, fontsize=14, verticalalignment='top', bbox=props) + +plt.show() diff --git a/examples/recipes/share_axis_lims_views.py b/examples/recipes/share_axis_lims_views.py index b80393afb848..6b266f8a6ae8 100644 --- a/examples/recipes/share_axis_lims_views.py +++ b/examples/recipes/share_axis_lims_views.py @@ -17,9 +17,9 @@ t = np.arange(0, 10, 0.01) ax1 = plt.subplot(211) - ax1.plot(t, np.sin(2*np.pi*t)) ax2 = plt.subplot(212, sharex=ax1) - ax2.plot(t, np.sin(4*np.pi*t)) + +plt.show() diff --git a/examples/recipes/transparent_legends.py b/examples/recipes/transparent_legends.py index 0219d5fe5f48..3aa6f2ee6066 100644 --- a/examples/recipes/transparent_legends.py +++ b/examples/recipes/transparent_legends.py @@ -29,3 +29,5 @@ ax.legend(loc='best', fancybox=True, framealpha=0.5) ax.set_title('fancy, transparent legends') + +plt.show() diff --git a/examples/shapes_and_collections/hatch_demo.py b/examples/shapes_and_collections/hatch_demo.py index 2785d6d35a29..4379d13839a7 100644 --- a/examples/shapes_and_collections/hatch_demo.py +++ b/examples/shapes_and_collections/hatch_demo.py @@ -9,14 +9,13 @@ import matplotlib.pyplot as plt from matplotlib.patches import Ellipse, Polygon -fig = plt.figure() -ax1 = fig.add_subplot(131) +fig, (ax1, ax2, ax3) = plt.subplots(3) + ax1.bar(range(1, 5), range(1, 5), color='red', edgecolor='black', hatch="/") ax1.bar(range(1, 5), [6] * 4, bottom=range(1, 5), color='blue', edgecolor='black', hatch='//') ax1.set_xticks([1.5, 2.5, 3.5, 4.5]) -ax2 = fig.add_subplot(132) bars = ax2.bar(range(1, 5), range(1, 5), color='yellow', ecolor='black') + \ ax2.bar(range(1, 5), [6] * 4, bottom=range(1, 5), color='green', ecolor='black') @@ -26,7 +25,6 @@ for bar, pattern in zip(bars, patterns): bar.set_hatch(pattern) -ax3 = fig.add_subplot(133) ax3.fill([1, 3, 3, 1], [1, 1, 2, 2], fill=False, hatch='\\') ax3.add_patch(Ellipse((4, 1.5), 4, 0.5, fill=False, hatch='*')) ax3.add_patch(Polygon([[0, 0], [4, 1.1], [6, 2.5], [2, 1.4]], closed=True, diff --git a/examples/style_sheets/fivethirtyeight.py b/examples/style_sheets/fivethirtyeight.py index f7653171b795..64b7ab07b6a6 100644 --- a/examples/style_sheets/fivethirtyeight.py +++ b/examples/style_sheets/fivethirtyeight.py @@ -7,7 +7,7 @@ tries to replicate the styles from FiveThirtyEight.com. """ -from matplotlib import pyplot as plt +import matplotlib.pyplot as plt import numpy as np diff --git a/examples/style_sheets/plot_solarizedlight2.py b/examples/style_sheets/plot_solarizedlight2.py index 79db70195458..b1a30b6fe14b 100644 --- a/examples/style_sheets/plot_solarizedlight2.py +++ b/examples/style_sheets/plot_solarizedlight2.py @@ -20,7 +20,7 @@ - Create alpha values for bar and stacked charts. .33 or .5 - Apply Layout Rules """ -from matplotlib import pyplot as plt +import matplotlib.pyplot as plt import numpy as np x = np.linspace(0, 10) with plt.style.context('Solarize_Light2'): diff --git a/examples/subplots_axes_and_figures/custom_figure_class.py b/examples/subplots_axes_and_figures/custom_figure_class.py index 6340d768acca..7e7b92721739 100644 --- a/examples/subplots_axes_and_figures/custom_figure_class.py +++ b/examples/subplots_axes_and_figures/custom_figure_class.py @@ -6,7 +6,8 @@ You can pass a custom Figure constructor to figure if you want to derive from the default Figure. This simple example creates a figure with a figure title. """ -from matplotlib.pyplot import figure, show + +import matplotlib.pyplot as plt from matplotlib.figure import Figure @@ -20,8 +21,8 @@ def __init__(self, *args, **kwargs): self.text(0.5, 0.95, figtitle, ha='center') -fig = figure(FigureClass=MyFigure, figtitle='my title') -ax = fig.add_subplot(111) +fig = plt.figure(FigureClass=MyFigure, figtitle='my title') +ax = fig.subplots() ax.plot([1, 2, 3]) -show() +plt.show() diff --git a/examples/text_labels_and_annotations/mathtext_demo.py b/examples/text_labels_and_annotations/mathtext_demo.py index e2b03da638b9..836f626ee403 100644 --- a/examples/text_labels_and_annotations/mathtext_demo.py +++ b/examples/text_labels_and_annotations/mathtext_demo.py @@ -3,29 +3,24 @@ Mathtext Demo ============= -Use matplotlib's internal LaTeX parser and layout engine. For true -latex rendering, see the text.usetex option +Use Matplotlib's internal LaTeX parser and layout engine. For true LaTeX +rendering, see the text.usetex option. """ -import numpy as np -from matplotlib.pyplot import figure, show -fig = figure() -fig.subplots_adjust(bottom=0.2) +import matplotlib.pyplot as plt -ax = fig.add_subplot(111) -ax.plot([1, 2, 3], 'r') -x = np.arange(0.0, 3.0, 0.1) +fig, ax = plt.subplots() + +ax.plot([1, 2, 3], 'r', label=r'$\sqrt{x^2}$') +ax.legend() -ax.grid(True) ax.set_xlabel(r'$\Delta_i^j$', fontsize=20) ax.set_ylabel(r'$\Delta_{i+1}^j$', fontsize=20) -tex = r'$\mathcal{R}\prod_{i=\alpha_{i+1}}^\infty a_i\sin(2 \pi f x_i)$' - -ax.text(1, 1.6, tex, fontsize=20, va='bottom') - -ax.legend([r"$\sqrt{x^2}$"]) - ax.set_title(r'$\Delta_i^j \hspace{0.4} \mathrm{versus} \hspace{0.4} ' r'\Delta_{i+1}^j$', fontsize=20) -show() +tex = r'$\mathcal{R}\prod_{i=\alpha_{i+1}}^\infty a_i\sin(2 \pi f x_i)$' +ax.text(1, 1.6, tex, fontsize=20, va='bottom') + +fig.tight_layout() +plt.show() diff --git a/examples/units/evans_test.py b/examples/units/evans_test.py index 85b6dbef1c78..36dcc240ea75 100644 --- a/examples/units/evans_test.py +++ b/examples/units/evans_test.py @@ -3,12 +3,12 @@ Evans test ========== -A mockup "Foo" units class which supports -conversion and different tick formatting depending on the "unit". -Here the "unit" is just a scalar conversion factor, but this example shows mpl -is entirely agnostic to what kind of units client packages use. - +A mockup "Foo" units class which supports conversion and different tick +formatting depending on the "unit". Here the "unit" is just a scalar +conversion factor, but this example shows that Matplotlib is entirely agnostic +to what kind of units client packages use. """ + from matplotlib.cbook import iterable import matplotlib.units as units import matplotlib.ticker as ticker @@ -75,24 +75,18 @@ def default_units(x, axis): y = [i for i in range(len(x))] -# plot specifying units -fig = plt.figure() +fig, (ax1, ax2) = plt.subplots(1, 2) fig.suptitle("Custom units") fig.subplots_adjust(bottom=0.2) -ax = fig.add_subplot(1, 2, 2) -ax.plot(x, y, 'o', xunits=2.0) -for label in ax.get_xticklabels(): - label.set_rotation(30) - label.set_ha('right') -ax.set_title("xunits = 2.0") +# plot specifying units +ax2.plot(x, y, 'o', xunits=2.0) +ax2.set_title("xunits = 2.0") +plt.setp(ax2.get_xticklabels(), rotation=30, ha='right') # plot without specifying units; will use the None branch for axisinfo -ax = fig.add_subplot(1, 2, 1) -ax.plot(x, y) # uses default units -ax.set_title('default units') -for label in ax.get_xticklabels(): - label.set_rotation(30) - label.set_ha('right') +ax1.plot(x, y) # uses default units +ax1.set_title('default units') +plt.setp(ax1.get_xticklabels(), rotation=30, ha='right') plt.show() diff --git a/examples/units/radian_demo.py b/examples/units/radian_demo.py index d6d960e2da1b..f9da342defcd 100644 --- a/examples/units/radian_demo.py +++ b/examples/units/radian_demo.py @@ -13,19 +13,18 @@ This example requires :download:`basic_units.py ` """ + +import matplotlib.pyplot as plt import numpy as np + from basic_units import radians, degrees, cos -from matplotlib.pyplot import figure, show x = [val*radians for val in np.arange(0, 15, 0.01)] -fig = figure() -fig.subplots_adjust(hspace=0.3) - -ax = fig.add_subplot(211) -line1, = ax.plot(x, cos(x), xunits=radians) +fig, axs = plt.subplots(2) -ax = fig.add_subplot(212) -line2, = ax.plot(x, cos(x), xunits=degrees) +axs[0].plot(x, cos(x), xunits=radians) +axs[1].plot(x, cos(x), xunits=degrees) -show() +fig.tight_layout() +plt.show() diff --git a/examples/units/units_sample.py b/examples/units/units_sample.py index 3ab5a9730bb5..0b99e2609b78 100644 --- a/examples/units/units_sample.py +++ b/examples/units/units_sample.py @@ -19,20 +19,16 @@ cms = cm * np.arange(0, 10, 2) -fig = plt.figure() +fig, axs = plt.subplots(2, 2) -ax1 = fig.add_subplot(2, 2, 1) -ax1.plot(cms, cms) +axs[0, 0].plot(cms, cms) -ax2 = fig.add_subplot(2, 2, 2) -ax2.plot(cms, cms, xunits=cm, yunits=inch) +axs[0, 1].plot(cms, cms, xunits=cm, yunits=inch) -ax3 = fig.add_subplot(2, 2, 3) -ax3.plot(cms, cms, xunits=inch, yunits=cm) -ax3.set_xlim(3, 6) # scalars are interpreted in current units +axs[1, 0].plot(cms, cms, xunits=inch, yunits=cm) +axs[1, 0].set_xlim(3, 6) # scalars are interpreted in current units -ax4 = fig.add_subplot(2, 2, 4) -ax4.plot(cms, cms, xunits=inch, yunits=inch) -ax4.set_xlim(3*cm, 6*cm) # cm are converted to inches +axs[1, 1].plot(cms, cms, xunits=inch, yunits=inch) +axs[1, 1].set_xlim(3*cm, 6*cm) # cm are converted to inches plt.show() diff --git a/examples/user_interfaces/embedding_in_gtk2_sgskip.py b/examples/user_interfaces/embedding_in_gtk2_sgskip.py index d8245cc8dda9..176809367f0c 100644 --- a/examples/user_interfaces/embedding_in_gtk2_sgskip.py +++ b/examples/user_interfaces/embedding_in_gtk2_sgskip.py @@ -9,7 +9,7 @@ import gtk from matplotlib.figure import Figure -from numpy import arange, sin, pi +import numpy as np # uncomment to select /GTK/GTKAgg/GTKCairo #from matplotlib.backends.backend_gtk import FigureCanvasGTK as FigureCanvas @@ -33,8 +33,8 @@ fig = Figure(figsize=(5, 4), dpi=100) ax = fig.add_subplot(111) -t = arange(0.0, 3.0, 0.01) -s = sin(2*pi*t) +t = np.arange(0.0, 3.0, 0.01) +s = np.sin(2*np.pi*t) ax.plot(t, s) diff --git a/examples/user_interfaces/embedding_in_gtk3_panzoom_sgskip.py b/examples/user_interfaces/embedding_in_gtk3_panzoom_sgskip.py index e4055bb3338a..ebead87f6ed6 100644 --- a/examples/user_interfaces/embedding_in_gtk3_panzoom_sgskip.py +++ b/examples/user_interfaces/embedding_in_gtk3_panzoom_sgskip.py @@ -3,15 +3,17 @@ Embedding In GTK3 Panzoom ========================= -demonstrate NavigationToolbar with GTK3 accessed via pygobject +Demonstrate NavigationToolbar with GTK3 accessed via pygobject. """ from gi.repository import Gtk +from matplotlib.backends.backend_gtk3 import ( + NavigationToolbar2GTK3 as NavigationToolbar) +from matplotlib.backends.backend_gtk3agg import ( + FigureCanvasGTK3Agg as FigureCanvas) from matplotlib.figure import Figure -from numpy import arange, sin, pi -from matplotlib.backends.backend_gtk3agg import FigureCanvasGTK3Agg as FigureCanvas -from matplotlib.backends.backend_gtk3 import NavigationToolbar2GTK3 as NavigationToolbar +import numpy as np win = Gtk.Window() win.connect("delete-event", Gtk.main_quit) @@ -20,8 +22,8 @@ f = Figure(figsize=(5, 4), dpi=100) a = f.add_subplot(1, 1, 1) -t = arange(0.0, 3.0, 0.01) -s = sin(2*pi*t) +t = np.arange(0.0, 3.0, 0.01) +s = np.sin(2*np.pi*t) a.plot(t, s) vbox = Gtk.VBox() diff --git a/examples/user_interfaces/embedding_in_gtk3_sgskip.py b/examples/user_interfaces/embedding_in_gtk3_sgskip.py index 70313042d4a4..a5e6271488ba 100644 --- a/examples/user_interfaces/embedding_in_gtk3_sgskip.py +++ b/examples/user_interfaces/embedding_in_gtk3_sgskip.py @@ -3,15 +3,16 @@ Embedding In GTK3 ================= -demonstrate adding a FigureCanvasGTK3Agg widget to a Gtk.ScrolledWindow -using GTK3 accessed via pygobject +Demonstrate adding a FigureCanvasGTK3Agg widget to a Gtk.ScrolledWindow using +GTK3 accessed via pygobject. """ from gi.repository import Gtk +from matplotlib.backends.backend_gtk3agg import ( + FigureCanvasGTK3Agg as FigureCanvas) from matplotlib.figure import Figure -from numpy import arange, sin, pi -from matplotlib.backends.backend_gtk3agg import FigureCanvasGTK3Agg as FigureCanvas +import numpy as np win = Gtk.Window() win.connect("delete-event", Gtk.main_quit) @@ -20,8 +21,8 @@ f = Figure(figsize=(5, 4), dpi=100) a = f.add_subplot(111) -t = arange(0.0, 3.0, 0.01) -s = sin(2*pi*t) +t = np.arange(0.0, 3.0, 0.01) +s = np.sin(2*np.pi*t) a.plot(t, s) sw = Gtk.ScrolledWindow() diff --git a/examples/user_interfaces/embedding_in_gtk_sgskip.py b/examples/user_interfaces/embedding_in_gtk_sgskip.py index 94d83a7010f2..7da96306a982 100644 --- a/examples/user_interfaces/embedding_in_gtk_sgskip.py +++ b/examples/user_interfaces/embedding_in_gtk_sgskip.py @@ -10,7 +10,7 @@ import gtk from matplotlib.figure import Figure -from numpy import arange, sin, pi +import numpy as np # uncomment to select /GTK/GTKAgg/GTKCairo #from matplotlib.backends.backend_gtk import FigureCanvasGTK as FigureCanvas @@ -25,8 +25,8 @@ f = Figure(figsize=(5, 4), dpi=100) a = f.add_subplot(111) -t = arange(0.0, 3.0, 0.01) -s = sin(2*pi*t) +t = np.arange(0.0, 3.0, 0.01) +s = np.sin(2*np.pi*t) a.plot(t, s) canvas = FigureCanvas(f) # a gtk.DrawingArea diff --git a/examples/user_interfaces/embedding_in_wx2_sgskip.py b/examples/user_interfaces/embedding_in_wx2_sgskip.py index f2c0e33042c6..a2847230739d 100644 --- a/examples/user_interfaces/embedding_in_wx2_sgskip.py +++ b/examples/user_interfaces/embedding_in_wx2_sgskip.py @@ -7,17 +7,14 @@ toolbar - comment out the add_toolbar line for no toolbar """ -from numpy import arange, sin, pi - import matplotlib - matplotlib.use('WXAgg') from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas - from matplotlib.backends.backend_wx import NavigationToolbar2Wx - from matplotlib.figure import Figure +import numpy as np + import wx import wx.lib.mixins.inspection as WIT @@ -29,8 +26,8 @@ def __init__(self): self.figure = Figure() self.axes = self.figure.add_subplot(111) - t = arange(0.0, 3.0, 0.01) - s = sin(2 * pi * t) + t = np.arange(0.0, 3.0, 0.01) + s = np.sin(2 * np.pi * t) self.axes.plot(t, s) self.canvas = FigureCanvas(self, -1, self.figure) diff --git a/examples/user_interfaces/embedding_in_wx4_sgskip.py b/examples/user_interfaces/embedding_in_wx4_sgskip.py index 29c80fbb9a74..a5abb97f3ca1 100644 --- a/examples/user_interfaces/embedding_in_wx4_sgskip.py +++ b/examples/user_interfaces/embedding_in_wx4_sgskip.py @@ -3,21 +3,17 @@ Embedding In Wx4 ================ -An example of how to use wx or wxagg in an application with a custom -toolbar +An example of how to use wx or wxagg in an application with a custom toolbar. """ -from numpy import arange, sin, pi - import matplotlib - matplotlib.use('WXAgg') from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas from matplotlib.backends.backend_wxagg import NavigationToolbar2WxAgg - from matplotlib.backends.backend_wx import _load_bitmap from matplotlib.figure import Figure -from numpy.random import rand + +import numpy as np import wx @@ -51,8 +47,8 @@ def _on_custom(self, evt): ax = self.canvas.figure.axes[0] # generate a random location can color - x, y = tuple(rand(2)) - rgb = tuple(rand(3)) + x, y = np.random.rand(2) + rgb = np.random.rand(3) # add the text and draw ax.text(x, y, 'You clicked me', @@ -69,8 +65,8 @@ def __init__(self): self.figure = Figure(figsize=(5, 4), dpi=100) self.axes = self.figure.add_subplot(111) - t = arange(0.0, 3.0, 0.01) - s = sin(2 * pi * t) + t = np.arange(0.0, 3.0, 0.01) + s = np.sin(2 * np.pi * t) self.axes.plot(t, s) diff --git a/examples/user_interfaces/fourier_demo_wx_sgskip.py b/examples/user_interfaces/fourier_demo_wx_sgskip.py index ef1aef255712..8a87dd974504 100644 --- a/examples/user_interfaces/fourier_demo_wx_sgskip.py +++ b/examples/user_interfaces/fourier_demo_wx_sgskip.py @@ -13,7 +13,6 @@ matplotlib.use('WXAgg') from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg from matplotlib.figure import Figure -from matplotlib.pyplot import gcf, setp class Knob(object): @@ -189,8 +188,7 @@ def mouseUp(self, evt): def draw(self): if not hasattr(self, 'subplot1'): - self.subplot1 = self.figure.add_subplot(211) - self.subplot2 = self.figure.add_subplot(212) + self.subplot1, self.subplot2 = self.figure.subplots(2) x1, y1, x2, y2 = self.compute(self.f0.value, self.A.value) color = (1., 0., 0.) self.lines += self.subplot1.plot(x1, y1, color=color, linewidth=2) @@ -230,8 +228,8 @@ def repaint(self): def setKnob(self, value): # Note, we ignore value arg here and just go by state of the params x1, y1, x2, y2 = self.compute(self.f0.value, self.A.value) - setp(self.lines[0], xdata=x1, ydata=y1) - setp(self.lines[1], xdata=x2, ydata=y2) + self.lines[0].set(xdata=x1, ydata=y1) + self.lines[1].set(xdata=x2, ydata=y2) self.repaint() diff --git a/examples/user_interfaces/mathtext_wx_sgskip.py b/examples/user_interfaces/mathtext_wx_sgskip.py index 178e1b91ea3a..b06162b2f0f3 100644 --- a/examples/user_interfaces/mathtext_wx_sgskip.py +++ b/examples/user_interfaces/mathtext_wx_sgskip.py @@ -9,10 +9,10 @@ import matplotlib matplotlib.use("WxAgg") -from numpy import arange, sin, pi, cos, log from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas from matplotlib.backends.backend_wx import NavigationToolbar2Wx, wxc from matplotlib.figure import Figure +import numpy as np import wx @@ -33,10 +33,10 @@ def mathtext_to_wxbitmap(s): ############################################################ functions = [ - (r'$\sin(2 \pi x)$', lambda x: sin(2*pi*x)), - (r'$\frac{4}{3}\pi x^3$', lambda x: (4.0/3.0)*pi*x**3), - (r'$\cos(2 \pi x)$', lambda x: cos(2*pi*x)), - (r'$\log(x)$', lambda x: log(x)) + (r'$\sin(2 \pi x)$', lambda x: np.sin(2*np.pi*x)), + (r'$\frac{4}{3}\pi x^3$', lambda x: (4.0/3.0)*np.pi*x**3), + (r'$\cos(2 \pi x)$', lambda x: np.cos(2*np.pi*x)), + (r'$\log(x)$', lambda x: np.log(x)) ] @@ -107,7 +107,7 @@ def OnChangePlot(self, event): self.change_plot(event.GetId() - 1000) def change_plot(self, plot_number): - t = arange(1.0, 3.0, 0.01) + t = np.arange(1.0, 3.0, 0.01) s = functions[plot_number][1](t) self.axes.clear() self.axes.plot(t, s) diff --git a/examples/user_interfaces/mpl_with_glade_316_sgskip.py b/examples/user_interfaces/mpl_with_glade_316_sgskip.py index 1fb9c7ecd0a2..b5cb5a6637fb 100644 --- a/examples/user_interfaces/mpl_with_glade_316_sgskip.py +++ b/examples/user_interfaces/mpl_with_glade_316_sgskip.py @@ -4,12 +4,14 @@ ========================= """ + from gi.repository import Gtk from matplotlib.figure import Figure from matplotlib.axes import Subplot -from numpy import arange, sin, pi -from matplotlib.backends.backend_gtk3agg import FigureCanvasGTK3Agg as FigureCanvas +from matplotlib.backends.backend_gtk3agg import ( + FigureCanvasGTK3Agg as FigureCanvas) +import numpy as np class Window1Signals(object): @@ -27,8 +29,8 @@ def main(): # Start of Matplotlib specific code figure = Figure(figsize=(8, 6), dpi=71) axis = figure.add_subplot(111) - t = arange(0.0, 3.0, 0.01) - s = sin(2*pi*t) + t = np.arange(0.0, 3.0, 0.01) + s = np.sin(2*np.pi*t) axis.plot(t, s) axis.set_xlabel('time [s]') diff --git a/examples/user_interfaces/mpl_with_glade_sgskip.py b/examples/user_interfaces/mpl_with_glade_sgskip.py index 2a088a53e4cc..ab2652b1365d 100644 --- a/examples/user_interfaces/mpl_with_glade_sgskip.py +++ b/examples/user_interfaces/mpl_with_glade_sgskip.py @@ -14,7 +14,7 @@ from matplotlib.backends.backend_gtkagg import NavigationToolbar2GTKAgg as NavigationToolbar from matplotlib.widgets import SpanSelector -from numpy import arange, sin, pi +import numpy as np import gtk import gtk.glade @@ -52,8 +52,8 @@ def __init__(self): self.figure = Figure(figsize=(8, 6), dpi=72) self.axis = self.figure.add_subplot(111) - t = arange(0.0, 3.0, 0.01) - s = sin(2*pi*t) + t = np.arange(0.0, 3.0, 0.01) + s = np.sin(2*np.pi*t) self.axis.plot(t, s) self.axis.set_xlabel('time (s)') self.axis.set_ylabel('voltage') diff --git a/examples/user_interfaces/wxcursor_demo_sgskip.py b/examples/user_interfaces/wxcursor_demo_sgskip.py index 74efb43bf77c..4fe9eab91c08 100644 --- a/examples/user_interfaces/wxcursor_demo_sgskip.py +++ b/examples/user_interfaces/wxcursor_demo_sgskip.py @@ -3,7 +3,7 @@ WXcursor Demo ============= -Example to draw a cursor and report the data coords in wx +Example to draw a cursor and report the data coords in wx. """ import matplotlib @@ -12,7 +12,7 @@ from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas from matplotlib.backends.backend_wx import NavigationToolbar2Wx, wxc from matplotlib.figure import Figure -from numpy import arange, sin, pi +import numpy as np import wx @@ -26,8 +26,8 @@ def __init__(self, ): self.figure = Figure() self.axes = self.figure.add_subplot(111) - t = arange(0.0, 3.0, 0.01) - s = sin(2*pi*t) + t = np.arange(0.0, 3.0, 0.01) + s = np.sin(2*np.pi*t) self.axes.plot(t, s) self.axes.set_xlabel('t') diff --git a/examples/widgets/multicursor.py b/examples/widgets/multicursor.py index 5137512065f8..7622792dd222 100644 --- a/examples/widgets/multicursor.py +++ b/examples/widgets/multicursor.py @@ -5,9 +5,8 @@ Showing a cursor on multiple plots simultaneously. -This example generates two subplots and on hovering -the cursor over data in one subplot, the values of that datapoint -are shown in both respectively. +This example generates two subplots and on hovering the cursor over data in one +subplot, the values of that datapoint are shown in both respectively. """ import numpy as np import matplotlib.pyplot as plt @@ -16,12 +15,9 @@ t = np.arange(0.0, 2.0, 0.01) s1 = np.sin(2*np.pi*t) s2 = np.sin(4*np.pi*t) -fig = plt.figure() -ax1 = fig.add_subplot(211) -ax1.plot(t, s1) - -ax2 = fig.add_subplot(212, sharex=ax1) +fig, (ax1, ax2) = plt.subplots(2, sharex=True) +ax1.plot(t, s1) ax2.plot(t, s2) multi = MultiCursor(fig.canvas, (ax1, ax2), color='r', lw=1) diff --git a/examples/widgets/span_selector.py b/examples/widgets/span_selector.py index 140b45c001fd..854defc87a0f 100644 --- a/examples/widgets/span_selector.py +++ b/examples/widgets/span_selector.py @@ -13,17 +13,17 @@ # Fixing random state for reproducibility np.random.seed(19680801) -fig = plt.figure(figsize=(8, 6)) -ax = fig.add_subplot(211, facecolor='#FFFFCC') +fig, (ax1, ax2) = plt.subplots(2, figsize=(8, 6)) +ax1.set(facecolor='#FFFFCC') x = np.arange(0.0, 5.0, 0.01) y = np.sin(2*np.pi*x) + 0.5*np.random.randn(len(x)) -ax.plot(x, y, '-') -ax.set_ylim(-2, 2) -ax.set_title('Press left mouse button and drag to test') +ax1.plot(x, y, '-') +ax1.set_ylim(-2, 2) +ax1.set_title('Press left mouse button and drag to test') -ax2 = fig.add_subplot(212, facecolor='#FFFFCC') +ax2.set(facecolor='#FFFFCC') line2, = ax2.plot(x, y, '-') @@ -39,7 +39,7 @@ def onselect(xmin, xmax): fig.canvas.draw() # set useblit True on gtkagg for enhanced performance -span = SpanSelector(ax, onselect, 'horizontal', useblit=True, +span = SpanSelector(ax1, onselect, 'horizontal', useblit=True, rectprops=dict(alpha=0.5, facecolor='red')) diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index a47486369916..9109704910d0 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -12,7 +12,6 @@ import numpy as np from numpy import ma -from numpy import arange from cycler import cycler import pytest @@ -4606,10 +4605,10 @@ def test_set_get_ticklabels(): fig, ax = plt.subplots(2) ha = ['normal', 'set_x/yticklabels'] - ax[0].plot(arange(10)) + ax[0].plot(np.arange(10)) ax[0].set_title(ha[0]) - ax[1].plot(arange(10)) + ax[1].plot(np.arange(10)) ax[1].set_title(ha[1]) # set ticklabel to 1 plot in normal way diff --git a/lib/matplotlib/tests/test_image.py b/lib/matplotlib/tests/test_image.py index ca3443a78445..ff9b7d238792 100644 --- a/lib/matplotlib/tests/test_image.py +++ b/lib/matplotlib/tests/test_image.py @@ -140,9 +140,8 @@ def test_imsave(): # So we do the traditional case (dpi == 1), and the new case (dpi # == 100) and read the resulting PNG files back in and make sure # the data is 100% identical. - from numpy import random - random.seed(1) - data = random.rand(256, 128) + np.random.seed(1) + data = np.random.rand(256, 128) buff_dpi1 = io.BytesIO() plt.imsave(buff_dpi1, data, dpi=1) @@ -173,11 +172,10 @@ def test_imsave_color_alpha(): # Test that imsave accept arrays with ndim=3 where the third dimension is # color and alpha without raising any exceptions, and that the data is # acceptably preserved through a save/read roundtrip. - from numpy import random - random.seed(1) + np.random.seed(1) for origin in ['lower', 'upper']: - data = random.rand(16, 16, 4) + data = np.random.rand(16, 16, 4) buff = io.BytesIO() plt.imsave(buff, data, origin=origin, format="png") pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy