From e53876ae5a66c29160aceab46f468e289d28a8e0 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sun, 28 May 2017 01:55:38 -0400 Subject: [PATCH 1/5] Use standard NumPy import in pylab examples. --- examples/animation/image_slices_viewer.py | 9 +++++---- examples/event_handling/pick_event_demo2.py | 8 ++++---- examples/event_handling/zoom_window.py | 4 ++-- examples/pylab_examples/ellipse_demo.py | 10 ++++++---- examples/pylab_examples/pcolor_demo.py | 4 ++-- examples/pylab_examples/spy_demos.py | 4 ++-- examples/pylab_examples/tricontour_vs_griddata.py | 7 +++---- examples/pylab_examples/vline_hline_demo.py | 3 +-- examples/subplots_axes_and_figures/subplot_toolbar.py | 10 +++++----- examples/units/units_sample.py | 4 ++-- .../user_interfaces/histogram_demo_canvasagg_sgskip.py | 7 +++---- examples/userdemo/annotate_text_arrow.py | 10 +++++----- 12 files changed, 40 insertions(+), 40 deletions(-) diff --git a/examples/animation/image_slices_viewer.py b/examples/animation/image_slices_viewer.py index a6ae072f9560..b8997b531396 100644 --- a/examples/animation/image_slices_viewer.py +++ b/examples/animation/image_slices_viewer.py @@ -5,7 +5,8 @@ """ from __future__ import print_function -import numpy + +import numpy as np import matplotlib.pyplot as plt @@ -24,9 +25,9 @@ def __init__(self, ax, X): def onscroll(self, event): print("%s %s" % (event.button, event.step)) if event.button == 'up': - self.ind = numpy.clip(self.ind + 1, 0, self.slices - 1) + self.ind = np.clip(self.ind + 1, 0, self.slices - 1) else: - self.ind = numpy.clip(self.ind - 1, 0, self.slices - 1) + self.ind = np.clip(self.ind - 1, 0, self.slices - 1) self.update() def update(self): @@ -37,7 +38,7 @@ def update(self): fig, ax = plt.subplots(1, 1) -X = numpy.random.rand(20, 20, 40) +X = np.random.rand(20, 20, 40) tracker = IndexTracker(ax, X) diff --git a/examples/event_handling/pick_event_demo2.py b/examples/event_handling/pick_event_demo2.py index a8da484b47bb..48ac59e0ae26 100644 --- a/examples/event_handling/pick_event_demo2.py +++ b/examples/event_handling/pick_event_demo2.py @@ -7,13 +7,13 @@ mean vs stddev. When you click on one of the mu, sigma points, plot the raw data from the dataset that generated the mean and stddev. """ -import numpy +import numpy as np import matplotlib.pyplot as plt -X = numpy.random.rand(100, 1000) -xs = numpy.mean(X, axis=1) -ys = numpy.std(X, axis=1) +X = np.random.rand(100, 1000) +xs = np.mean(X, axis=1) +ys = np.std(X, axis=1) fig, ax = plt.subplots() ax.set_title('click on point to plot time series') diff --git a/examples/event_handling/zoom_window.py b/examples/event_handling/zoom_window.py index 21c343bc47ec..b84afeb67daf 100644 --- a/examples/event_handling/zoom_window.py +++ b/examples/event_handling/zoom_window.py @@ -14,7 +14,7 @@ points**2, so their size is independent of the zoom """ from matplotlib.pyplot import figure, show -import numpy +import numpy as np figsrc = figure() figzoom = figure() @@ -23,7 +23,7 @@ autoscale_on=False) axsrc.set_title('Click to zoom') axzoom.set_title('zoom window') -x, y, s, c = numpy.random.rand(4, 200) +x, y, s, c = np.random.rand(4, 200) s *= 200 diff --git a/examples/pylab_examples/ellipse_demo.py b/examples/pylab_examples/ellipse_demo.py index 18606fa55fb4..7830a1c080c2 100644 --- a/examples/pylab_examples/ellipse_demo.py +++ b/examples/pylab_examples/ellipse_demo.py @@ -5,20 +5,22 @@ """ import matplotlib.pyplot as plt -import numpy.random as rnd +import numpy as np from matplotlib.patches import Ellipse NUM = 250 -ells = [Ellipse(xy=rnd.rand(2)*10, width=rnd.rand(), height=rnd.rand(), angle=rnd.rand()*360) +ells = [Ellipse(xy=np.random.rand(2)*10, + width=np.random.rand(), height=np.random.rand(), + angle=np.random.rand()*360) for i in range(NUM)] fig, ax = plt.subplots(subplot_kw={'aspect': 'equal'}) for e in ells: ax.add_artist(e) e.set_clip_box(ax.bbox) - e.set_alpha(rnd.rand()) - e.set_facecolor(rnd.rand(3)) + e.set_alpha(np.random.rand()) + e.set_facecolor(np.random.rand(3)) ax.set_xlim(0, 10) ax.set_ylim(0, 10) diff --git a/examples/pylab_examples/pcolor_demo.py b/examples/pylab_examples/pcolor_demo.py index 993560ee33e3..68b1b7e1d10c 100644 --- a/examples/pylab_examples/pcolor_demo.py +++ b/examples/pylab_examples/pcolor_demo.py @@ -10,15 +10,15 @@ """ import matplotlib.pyplot as plt import numpy as np -from numpy.random import rand from matplotlib.colors import LogNorm from matplotlib.mlab import bivariate_normal + ############################################################################### # A simple pcolor demo # -------------------- -Z = rand(6, 10) +Z = np.random.rand(6, 10) plt.subplot(2, 1, 1) c = plt.pcolor(Z) diff --git a/examples/pylab_examples/spy_demos.py b/examples/pylab_examples/spy_demos.py index bbf4201ff5ad..a0b6cfd0206a 100644 --- a/examples/pylab_examples/spy_demos.py +++ b/examples/pylab_examples/spy_demos.py @@ -7,7 +7,7 @@ """ from matplotlib.pyplot import figure, show -import numpy +import numpy as np fig = figure() ax1 = fig.add_subplot(221) @@ -15,7 +15,7 @@ ax3 = fig.add_subplot(223) ax4 = fig.add_subplot(224) -x = numpy.random.randn(20, 20) +x = np.random.randn(20, 20) x[5] = 0. x[:, 12] = 0. diff --git a/examples/pylab_examples/tricontour_vs_griddata.py b/examples/pylab_examples/tricontour_vs_griddata.py index 3b3d67f35bac..7ae6bbf84893 100644 --- a/examples/pylab_examples/tricontour_vs_griddata.py +++ b/examples/pylab_examples/tricontour_vs_griddata.py @@ -9,16 +9,15 @@ import matplotlib.pyplot as plt import matplotlib.tri as tri import numpy as np -import numpy.random as rnd import matplotlib.mlab as mlab import time -rnd.seed(0) +np.random.seed(0) npts = 200 ngridx = 100 ngridy = 200 -x = rnd.uniform(-2, 2, npts) -y = rnd.uniform(-2, 2, npts) +x = np.random.uniform(-2, 2, npts) +y = np.random.uniform(-2, 2, npts) z = x*np.exp(-x**2 - y**2) # griddata and contour. diff --git a/examples/pylab_examples/vline_hline_demo.py b/examples/pylab_examples/vline_hline_demo.py index 1959b4af8e5e..dcb0fb733db9 100644 --- a/examples/pylab_examples/vline_hline_demo.py +++ b/examples/pylab_examples/vline_hline_demo.py @@ -9,7 +9,6 @@ import matplotlib.pyplot as plt from matplotlib.transforms import blended_transform_factory as btf import numpy as np -import numpy.random as rnd def f(t): @@ -19,7 +18,7 @@ def f(t): t = np.arange(0.0, 5.0, 0.1) s = f(t) -nse = rnd.normal(0.0, 0.3, t.shape) * s +nse = np.random.normal(0.0, 0.3, t.shape) * s fig = plt.figure(figsize=(12, 6)) vax = fig.add_subplot(121) diff --git a/examples/subplots_axes_and_figures/subplot_toolbar.py b/examples/subplots_axes_and_figures/subplot_toolbar.py index ed2c7611d8a8..343a35bdfb2b 100644 --- a/examples/subplots_axes_and_figures/subplot_toolbar.py +++ b/examples/subplots_axes_and_figures/subplot_toolbar.py @@ -5,17 +5,17 @@ """ import matplotlib.pyplot as plt -import numpy.random as rnd +import numpy as np fig = plt.figure() plt.subplot(221) -plt.imshow(rnd.random((100, 100))) +plt.imshow(np.random.random((100, 100))) plt.subplot(222) -plt.imshow(rnd.random((100, 100))) +plt.imshow(np.random.random((100, 100))) plt.subplot(223) -plt.imshow(rnd.random((100, 100))) +plt.imshow(np.random.random((100, 100))) plt.subplot(224) -plt.imshow(rnd.random((100, 100))) +plt.imshow(np.random.random((100, 100))) plt.subplot_tool() plt.show() diff --git a/examples/units/units_sample.py b/examples/units/units_sample.py index dfa2333d7dc3..3ab5a9730bb5 100644 --- a/examples/units/units_sample.py +++ b/examples/units/units_sample.py @@ -15,9 +15,9 @@ """ from basic_units import cm, inch import matplotlib.pyplot as plt -import numpy +import numpy as np -cms = cm * numpy.arange(0, 10, 2) +cms = cm * np.arange(0, 10, 2) fig = plt.figure() diff --git a/examples/user_interfaces/histogram_demo_canvasagg_sgskip.py b/examples/user_interfaces/histogram_demo_canvasagg_sgskip.py index 07ddaaf669b7..f3cc2cca4e09 100644 --- a/examples/user_interfaces/histogram_demo_canvasagg_sgskip.py +++ b/examples/user_interfaces/histogram_demo_canvasagg_sgskip.py @@ -15,8 +15,7 @@ from matplotlib.backends.backend_agg import FigureCanvasAgg from matplotlib.figure import Figure from matplotlib.mlab import normpdf -from numpy.random import randn -import numpy +import numpy as np fig = Figure(figsize=(5, 4), dpi=100) ax = fig.add_subplot(111) @@ -24,7 +23,7 @@ canvas = FigureCanvasAgg(fig) mu, sigma = 100, 15 -x = mu + sigma*randn(10000) +x = mu + sigma * np.random.randn(10000) # the histogram of the data n, bins, patches = ax.hist(x, 50, normed=1) @@ -52,7 +51,7 @@ if 0: # convert to a numpy array - X = numpy.fromstring(s, numpy.uint8).reshape((h, w, 3)) + X = np.fromstring(s, np.uint8).reshape((h, w, 3)) if 0: # pass off to PIL diff --git a/examples/userdemo/annotate_text_arrow.py b/examples/userdemo/annotate_text_arrow.py index b698fd4830a3..193fe52efbba 100644 --- a/examples/userdemo/annotate_text_arrow.py +++ b/examples/userdemo/annotate_text_arrow.py @@ -5,16 +5,16 @@ """ -import numpy.random +import numpy as np import matplotlib.pyplot as plt fig, ax = plt.subplots(figsize=(5, 5)) ax.set_aspect(1) -x1 = -1 + numpy.random.randn(100) -y1 = -1 + numpy.random.randn(100) -x2 = 1. + numpy.random.randn(100) -y2 = 1. + numpy.random.randn(100) +x1 = -1 + np.random.randn(100) +y1 = -1 + np.random.randn(100) +x2 = 1. + np.random.randn(100) +y2 = 1. + np.random.randn(100) ax.scatter(x1, y1, color="r") ax.scatter(x2, y2, color="g") From 4df2bb7e28bf5abf8e88064c0fa8625b0743900f Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sun, 28 May 2017 04:38:07 -0400 Subject: [PATCH 2/5] Allow wraparound in image slice viewer example. Also, drop the more expensive `np.clip` call. --- examples/animation/image_slices_viewer.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/animation/image_slices_viewer.py b/examples/animation/image_slices_viewer.py index b8997b531396..70646973ec98 100644 --- a/examples/animation/image_slices_viewer.py +++ b/examples/animation/image_slices_viewer.py @@ -25,9 +25,9 @@ def __init__(self, ax, X): def onscroll(self, event): print("%s %s" % (event.button, event.step)) if event.button == 'up': - self.ind = np.clip(self.ind + 1, 0, self.slices - 1) + self.ind = (self.ind + 1) % self.slices else: - self.ind = np.clip(self.ind - 1, 0, self.slices - 1) + self.ind = (self.ind - 1) % self.slices self.update() def update(self): From 5b8efe1b6689cb2c1ef3f211faa958111fb1c137 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sun, 28 May 2017 05:27:58 -0400 Subject: [PATCH 3/5] Avoid leaks with cbook.get_sample_data. --- examples/frontpage/membrane.py | 4 +-- .../image_clip_path.py | 4 +-- .../images_contours_and_fields/image_demo.py | 8 ++--- examples/pylab_examples/mri_demo.py | 7 ++-- examples/pylab_examples/mri_with_eeg.py | 10 +++--- .../showcase/bachelors_degrees_by_gender.py | 4 +-- .../topographic_hillshading.py | 32 ++++++++++--------- 7 files changed, 34 insertions(+), 35 deletions(-) diff --git a/examples/frontpage/membrane.py b/examples/frontpage/membrane.py index 4a99e6de1429..4e126eceda5f 100644 --- a/examples/frontpage/membrane.py +++ b/examples/frontpage/membrane.py @@ -11,8 +11,8 @@ import numpy as np -datafile = cbook.get_sample_data('membrane.dat', asfileobj=False) -x = np.fromfile(datafile, np.float32) +with cbook.get_sample_data('membrane.dat') as datafile: + x = np.fromfile(datafile, np.float32) # 0.0005 is the sample interval fig, ax = plt.subplots() diff --git a/examples/images_contours_and_fields/image_clip_path.py b/examples/images_contours_and_fields/image_clip_path.py index e005b6538c51..e444ee1195bf 100644 --- a/examples/images_contours_and_fields/image_clip_path.py +++ b/examples/images_contours_and_fields/image_clip_path.py @@ -10,8 +10,8 @@ import matplotlib.cbook as cbook -image_file = cbook.get_sample_data('grace_hopper.png') -image = plt.imread(image_file) +with cbook.get_sample_data('grace_hopper.png') as image_file: + image = plt.imread(image_file) fig, ax = plt.subplots() im = ax.imshow(image) diff --git a/examples/images_contours_and_fields/image_demo.py b/examples/images_contours_and_fields/image_demo.py index 40cc412bd38f..d811ef4fe30a 100644 --- a/examples/images_contours_and_fields/image_demo.py +++ b/examples/images_contours_and_fields/image_demo.py @@ -41,8 +41,8 @@ # It is also possible to show images of pictures. # A sample image -image_file = cbook.get_sample_data('ada.png') -image = plt.imread(image_file) +with cbook.get_sample_data('ada.png') as image_file: + image = plt.imread(image_file) fig, ax = plt.subplots() ax.imshow(image) @@ -53,8 +53,8 @@ w, h = 512, 512 -datafile = cbook.get_sample_data('ct.raw.gz', asfileobj=True) -s = datafile.read() +with cbook.get_sample_data('ct.raw.gz', asfileobj=True) as datafile: + s = datafile.read() A = np.fromstring(s, np.uint16).astype(float).reshape((w, h)) A /= A.max() diff --git a/examples/pylab_examples/mri_demo.py b/examples/pylab_examples/mri_demo.py index 7a94529be9d1..0f2e873c1ae9 100644 --- a/examples/pylab_examples/mri_demo.py +++ b/examples/pylab_examples/mri_demo.py @@ -12,13 +12,12 @@ import matplotlib.cm as cm import numpy as np -fig, ax = plt.subplots(num="MRI_demo") # Data are 256x256 16 bit integers -dfile = cbook.get_sample_data('s1045.ima.gz') -im = np.fromstring(dfile.read(), np.uint16).reshape((256, 256)) -dfile.close() +with cbook.get_sample_data('s1045.ima.gz') as dfile: + im = np.fromstring(dfile.read(), np.uint16).reshape((256, 256)) +fig, ax = plt.subplots(num="MRI_demo") ax.imshow(im, cmap=cm.gray) ax.axis('off') diff --git a/examples/pylab_examples/mri_with_eeg.py b/examples/pylab_examples/mri_with_eeg.py index da92dd0aea8b..0fd3be3d6eda 100644 --- a/examples/pylab_examples/mri_with_eeg.py +++ b/examples/pylab_examples/mri_with_eeg.py @@ -20,9 +20,8 @@ fig = plt.figure("MRI_with_EEG") # Load the MRI data (256x256 16 bit integers) -dfile = cbook.get_sample_data('s1045.ima.gz') -im = np.fromstring(dfile.read(), np.uint16).reshape((256, 256)) -dfile.close() +with cbook.get_sample_data('s1045.ima.gz') as dfile: + im = np.fromstring(dfile.read(), np.uint16).reshape((256, 256)) # Plot the MRI image ax0 = fig.add_subplot(2, 2, 1) @@ -43,9 +42,8 @@ # Load the EEG data numSamples, numRows = 800, 4 -eegfile = cbook.get_sample_data('eeg.dat', asfileobj=False) -print('Loading EEG %s' % eegfile) -data = np.fromfile(eegfile, dtype=float) +with cbook.get_sample_data('eeg.dat') as eegfile: + data = np.fromfile(eegfile, dtype=float) data.shape = (numSamples, numRows) t = 10.0 * np.arange(numSamples) / numSamples diff --git a/examples/showcase/bachelors_degrees_by_gender.py b/examples/showcase/bachelors_degrees_by_gender.py index 9bca3da11a96..1305770f584f 100644 --- a/examples/showcase/bachelors_degrees_by_gender.py +++ b/examples/showcase/bachelors_degrees_by_gender.py @@ -14,8 +14,8 @@ from matplotlib.mlab import csv2rec from matplotlib.cbook import get_sample_data -fname = get_sample_data('percent_bachelors_degrees_women_usa.csv') -gender_degree_data = csv2rec(fname) +with get_sample_data('percent_bachelors_degrees_women_usa.csv') as fname: + gender_degree_data = csv2rec(fname) # These are the colors that will be used in the plot color_sequence = ['#1f77b4', '#aec7e8', '#ff7f0e', '#ffbb78', '#2ca02c', diff --git a/examples/specialty_plots/topographic_hillshading.py b/examples/specialty_plots/topographic_hillshading.py index fd9fd90e13fd..cd197e09af72 100644 --- a/examples/specialty_plots/topographic_hillshading.py +++ b/examples/specialty_plots/topographic_hillshading.py @@ -21,22 +21,24 @@ from matplotlib.cbook import get_sample_data from matplotlib.colors import LightSource -dem = np.load(get_sample_data('jacksboro_fault_dem.npz')) -z = dem['elevation'] -#-- Optional dx and dy for accurate vertical exaggeration -------------------- -# If you need topographically accurate vertical exaggeration, or you don't want -# to guess at what *vert_exag* should be, you'll need to specify the cellsize -# of the grid (i.e. the *dx* and *dy* parameters). Otherwise, any *vert_exag* -# value you specify will be relative to the grid spacing of your input data -# (in other words, *dx* and *dy* default to 1.0, and *vert_exag* is calculated -# relative to those parameters). Similarly, *dx* and *dy* are assumed to be in -# the same units as your input z-values. Therefore, we'll need to convert the -# given dx and dy from decimal degrees to meters. -dx, dy = dem['dx'], dem['dy'] -dy = 111200 * dy -dx = 111200 * dx * np.cos(np.radians(dem['ymin'])) -#----------------------------------------------------------------------------- +with np.load(get_sample_data('jacksboro_fault_dem.npz')) as dem: + z = dem['elevation'] + + #-- Optional dx and dy for accurate vertical exaggeration ---------------- + # If you need topographically accurate vertical exaggeration, or you don't + # want to guess at what *vert_exag* should be, you'll need to specify the + # cellsize of the grid (i.e. the *dx* and *dy* parameters). Otherwise, any + # *vert_exag* value you specify will be relative to the grid spacing of + # your input data (in other words, *dx* and *dy* default to 1.0, and + # *vert_exag* is calculated relative to those parameters). Similarly, *dx* + # and *dy* are assumed to be in the same units as your input z-values. + # Therefore, we'll need to convert the given dx and dy from decimal degrees + # to meters. + dx, dy = dem['dx'], dem['dy'] + dy = 111200 * dy + dx = 111200 * dx * np.cos(np.radians(dem['ymin'])) + #------------------------------------------------------------------------- # Shade from the northwest, with the sun 45 degrees from horizontal ls = LightSource(azdeg=315, altdeg=45) From 426a712d99387ff8d09749f5d2d05af51067731f Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sun, 28 May 2017 05:41:38 -0400 Subject: [PATCH 4/5] Fix some typos in merged examples. --- examples/images_contours_and_fields/image_demo.py | 6 +++--- examples/pylab_examples/fancybox_demo.py | 6 +++--- examples/pylab_examples/psd_demo.py | 2 +- examples/user_interfaces/histogram_demo_canvasagg_sgskip.py | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/examples/images_contours_and_fields/image_demo.py b/examples/images_contours_and_fields/image_demo.py index d811ef4fe30a..d55bd905a4e2 100644 --- a/examples/images_contours_and_fields/image_demo.py +++ b/examples/images_contours_and_fields/image_demo.py @@ -138,9 +138,9 @@ ############################################################################### # You can specify whether images should be plotted with the array origin -# x[0,0] in the upper left or upper right by using the origin parameter. -# You can also control the default be setting image.origin in your -# matplotlibrc file; see http://matplotlib.org/matplotlibrc +# x[0,0] in the upper left or lower right by using the origin parameter. +# You can also control the default setting image.origin in your +# :ref:`matplotlibrc file ` x = np.arange(120).reshape((10, 12)) diff --git a/examples/pylab_examples/fancybox_demo.py b/examples/pylab_examples/fancybox_demo.py index 9b3b02314c2f..9d5465d51f2e 100644 --- a/examples/pylab_examples/fancybox_demo.py +++ b/examples/pylab_examples/fancybox_demo.py @@ -93,7 +93,7 @@ def test2(ax): #p_fancy.set_boxstyle("round", pad=0.1, rounding_size=0.2) ax.text(0.1, 0.8, - ' boxstyle="round,pad=0.1\n rounding\\_size=0.2"', + ' boxstyle="round,pad=0.1\n rounding_size=0.2"', size=10, transform=ax.transAxes) # draws control points for the fancy box. @@ -118,7 +118,7 @@ def test3(ax): ax.add_patch(p_fancy) ax.text(0.1, 0.8, - ' boxstyle="round,pad=0.1"\n mutation\\_scale=2', + ' boxstyle="round,pad=0.1"\n mutation_scale=2', size=10, transform=ax.transAxes) # draws control points for the fancy box. @@ -152,7 +152,7 @@ def test4(ax): ax.add_patch(p_fancy) ax.text(0.1, 0.8, - ' boxstyle="round,pad=0.3"\n mutation\\_aspect=.5', + ' boxstyle="round,pad=0.3"\n mutation_aspect=.5', size=10, transform=ax.transAxes) draw_bbox(ax, bb) diff --git a/examples/pylab_examples/psd_demo.py b/examples/pylab_examples/psd_demo.py index ba7cda9c086e..a60cefe9a5e3 100644 --- a/examples/pylab_examples/psd_demo.py +++ b/examples/pylab_examples/psd_demo.py @@ -5,7 +5,7 @@ Plotting Power Spectral Density (PSD) in Matplotlib. -The PSD is a common plot in the field of signal processing. Numpy has +The PSD is a common plot in the field of signal processing. NumPy has many useful libraries for computing a PSD. Below we demo a few examples of how this can be accomplished and visualized with Matplotlib. """ diff --git a/examples/user_interfaces/histogram_demo_canvasagg_sgskip.py b/examples/user_interfaces/histogram_demo_canvasagg_sgskip.py index f3cc2cca4e09..5fe6e82d1076 100644 --- a/examples/user_interfaces/histogram_demo_canvasagg_sgskip.py +++ b/examples/user_interfaces/histogram_demo_canvasagg_sgskip.py @@ -44,13 +44,13 @@ s = canvas.tostring_rgb() # save this and convert to bitmap as needed -# get the figure dimensions for creating bitmaps or numpy arrays, +# Get the figure dimensions for creating bitmaps or NumPy arrays, # etc. l, b, w, h = fig.bbox.bounds w, h = int(w), int(h) if 0: - # convert to a numpy array + # Convert to a NumPy array X = np.fromstring(s, np.uint8).reshape((h, w, 3)) if 0: From 869bd95b3d8eb4e333f303a7fd25cb84f1b66c6f Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Sun, 28 May 2017 06:02:36 -0400 Subject: [PATCH 5/5] Use OO interface more in merged examples. --- .../images_contours_and_fields/image_demo.py | 32 ++++----- examples/pylab_examples/line_collection.py | 5 +- examples/pylab_examples/major_minor_demo.py | 10 +-- examples/pylab_examples/pcolor_demo.py | 71 +++++++++---------- examples/pylab_examples/spy_demos.py | 16 ++--- examples/pylab_examples/stackplot_demo.py | 4 +- examples/statistics/barchart_demo.py | 39 +++++----- examples/statistics/boxplot_demo.py | 68 ++++++++++-------- examples/statistics/hexbin_demo.py | 19 +++-- .../subplot_toolbar.py | 18 ++--- .../legend_demo.py | 46 ++++++------ 11 files changed, 164 insertions(+), 164 deletions(-) diff --git a/examples/images_contours_and_fields/image_demo.py b/examples/images_contours_and_fields/image_demo.py index d55bd905a4e2..6400f6391109 100644 --- a/examples/images_contours_and_fields/image_demo.py +++ b/examples/images_contours_and_fields/image_demo.py @@ -58,14 +58,15 @@ A = np.fromstring(s, np.uint16).astype(float).reshape((w, h)) A /= A.max() +fig, ax = plt.subplots() extent = (0, 25, 0, 25) -im = plt.imshow(A, cmap=plt.cm.hot, origin='upper', extent=extent) +im = ax.imshow(A, cmap=plt.cm.hot, origin='upper', extent=extent) markers = [(15.9, 14.5), (16.8, 15)] x, y = zip(*markers) -plt.plot(x, y, 'o') +ax.plot(x, y, 'o') -plt.title('CT density') +ax.set_title('CT density') plt.show() @@ -121,17 +122,12 @@ # suggested. A = np.random.rand(5, 5) -plt.figure(1) -plt.imshow(A, interpolation='nearest') -plt.grid(True) - -plt.figure(2) -plt.imshow(A, interpolation='bilinear') -plt.grid(True) -plt.figure(3) -plt.imshow(A, interpolation='bicubic') -plt.grid(True) +fig, axs = plt.subplots(1, 3, figsize=(10, 3)) +for ax, interp in zip(axs, ['nearest', 'bilinear', 'bicubic']): + ax.imshow(A, interpolation=interp) + ax.set_title(interp.capitalize()) + ax.grid(True) plt.show() @@ -166,11 +162,13 @@ path = Path([[0, 1], [1, 0], [0, -1], [-1, 0], [0, 1]]) patch = PathPatch(path, facecolor='none') -plt.gca().add_patch(patch) -im = plt.imshow(Z, interpolation='bilinear', cmap=cm.gray, - origin='lower', extent=[-3, 3, -3, 3], - clip_path=patch, clip_on=True) +fig, ax = plt.subplots() +ax.add_patch(patch) + +im = ax.imshow(Z, interpolation='bilinear', cmap=cm.gray, + origin='lower', extent=[-3, 3, -3, 3], + clip_path=patch, clip_on=True) im.set_clip_path(patch) plt.show() diff --git a/examples/pylab_examples/line_collection.py b/examples/pylab_examples/line_collection.py index 211285027d77..b55ecb5e3f60 100644 --- a/examples/pylab_examples/line_collection.py +++ b/examples/pylab_examples/line_collection.py @@ -30,7 +30,7 @@ segs = np.ma.masked_where((segs > 50) & (segs < 60), segs) # We need to set the plot limits. -ax = plt.axes() +fig, ax = plt.subplots() ax.set_xlim(x.min(), x.max()) ax.set_ylim(ys.min(), ys.max()) @@ -60,7 +60,7 @@ ys = [x + i for i in x] # We need to set the plot limits, they will not autoscale -ax = plt.axes() +fig, ax = plt.subplots() ax.set_xlim(np.min(x), np.max(x)) ax.set_ylim(np.min(ys), np.max(ys)) @@ -77,7 +77,6 @@ linestyles='solid') line_segments.set_array(x) ax.add_collection(line_segments) -fig = plt.gcf() axcb = fig.colorbar(line_segments) axcb.set_label('Line Number') ax.set_title('Line Collection with mapped colors') diff --git a/examples/pylab_examples/major_minor_demo.py b/examples/pylab_examples/major_minor_demo.py index 76561779b3b6..d5f0b5b869ae 100644 --- a/examples/pylab_examples/major_minor_demo.py +++ b/examples/pylab_examples/major_minor_demo.py @@ -47,7 +47,7 @@ s = np.sin(0.1*np.pi*t)*np.exp(-t*0.01) fig, ax = plt.subplots() -plt.plot(t, s) +ax.plot(t, s) ax.xaxis.set_major_locator(majorLocator) ax.xaxis.set_major_formatter(majorFormatter) @@ -76,12 +76,12 @@ s = np.sin(2*np.pi*t)*np.exp(-t*0.01) fig, ax = plt.subplots() -plt.plot(t, s) +ax.plot(t, s) ax.xaxis.set_minor_locator(minorLocator) -plt.tick_params(which='both', width=2) -plt.tick_params(which='major', length=7) -plt.tick_params(which='minor', length=4, color='r') +ax.tick_params(which='both', width=2) +ax.tick_params(which='major', length=7) +ax.tick_params(which='minor', length=4, color='r') plt.show() diff --git a/examples/pylab_examples/pcolor_demo.py b/examples/pylab_examples/pcolor_demo.py index 68b1b7e1d10c..ce56253dbef0 100644 --- a/examples/pylab_examples/pcolor_demo.py +++ b/examples/pylab_examples/pcolor_demo.py @@ -20,13 +20,13 @@ Z = np.random.rand(6, 10) -plt.subplot(2, 1, 1) -c = plt.pcolor(Z) -plt.title('default: no edges') +fig, (ax0, ax1) = plt.subplots(2, 1) -plt.subplot(2, 1, 2) -c = plt.pcolor(Z, edgecolors='k', linewidths=4) -plt.title('thick edges') +c = ax0.pcolor(Z) +ax0.set_title('default: no edges') + +c = ax1.pcolor(Z, edgecolors='k', linewidths=4) +ax1.set_title('thick edges') plt.show() @@ -49,37 +49,35 @@ z = z[:-1, :-1] z_min, z_max = -np.abs(z).max(), np.abs(z).max() +fig, axs = plt.subplots(2, 2) -plt.subplot(2, 2, 1) -plt.pcolor(x, y, z, cmap='RdBu', vmin=z_min, vmax=z_max) -plt.title('pcolor') +ax = axs[0, 0] +c = ax.pcolor(x, y, z, cmap='RdBu', vmin=z_min, vmax=z_max) +ax.set_title('pcolor') # set the limits of the plot to the limits of the data -plt.axis([x.min(), x.max(), y.min(), y.max()]) -plt.colorbar() - +ax.axis([x.min(), x.max(), y.min(), y.max()]) +fig.colorbar(c, ax=ax) -plt.subplot(2, 2, 2) -plt.pcolormesh(x, y, z, cmap='RdBu', vmin=z_min, vmax=z_max) -plt.title('pcolormesh') +ax = axs[0, 1] +c = ax.pcolormesh(x, y, z, cmap='RdBu', vmin=z_min, vmax=z_max) +ax.set_title('pcolormesh') # set the limits of the plot to the limits of the data -plt.axis([x.min(), x.max(), y.min(), y.max()]) -plt.colorbar() - +ax.axis([x.min(), x.max(), y.min(), y.max()]) +fig.colorbar(c, ax=ax) -plt.subplot(2, 2, 3) -plt.imshow(z, cmap='RdBu', vmin=z_min, vmax=z_max, - extent=[x.min(), x.max(), y.min(), y.max()], - interpolation='nearest', origin='lower') -plt.title('image (nearest)') -plt.colorbar() +ax = axs[1, 0] +c = ax.imshow(z, cmap='RdBu', vmin=z_min, vmax=z_max, + extent=[x.min(), x.max(), y.min(), y.max()], + interpolation='nearest', origin='lower') +ax.set_title('image (nearest)') +fig.colorbar(c, ax=ax) +ax = axs[1, 1] +c = ax.pcolorfast(x, y, z, cmap='RdBu', vmin=z_min, vmax=z_max) +ax.set_title('pcolorfast') +fig.colorbar(c, ax=ax) -ax = plt.subplot(2, 2, 4) -ax.pcolorfast(x, y, z, cmap='RdBu', vmin=z_min, vmax=z_max) -plt.title('pcolorfast') -plt.colorbar() - -plt.subplots_adjust(wspace=0.5, hspace=0.5) +fig.subplots_adjust(wspace=0.5, hspace=0.5) plt.show() @@ -98,12 +96,13 @@ # linear scale only shows the spike. Z1 = bivariate_normal(X, Y, 0.1, 0.2, 1.0, 1.0) + 0.1 * bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0) -plt.subplot(2, 1, 1) -plt.pcolor(X, Y, Z1, norm=LogNorm(vmin=Z1.min(), vmax=Z1.max()), cmap='PuBu_r') -plt.colorbar() +fig, (ax0, ax1) = plt.subplots(2, 1) + +c = ax0.pcolor(X, Y, Z1, + norm=LogNorm(vmin=Z1.min(), vmax=Z1.max()), cmap='PuBu_r') +fig.colorbar(c, ax=ax0) -plt.subplot(2, 1, 2) -plt.pcolor(X, Y, Z1, cmap='PuBu_r') -plt.colorbar() +c = ax1.pcolor(X, Y, Z1, cmap='PuBu_r') +fig.colorbar(c, ax=ax1) plt.show() diff --git a/examples/pylab_examples/spy_demos.py b/examples/pylab_examples/spy_demos.py index a0b6cfd0206a..2a518375ec6e 100644 --- a/examples/pylab_examples/spy_demos.py +++ b/examples/pylab_examples/spy_demos.py @@ -6,17 +6,17 @@ Plot the sparsity pattern of arrays """ -from matplotlib.pyplot import figure, show +import matplotlib.pyplot as plt import numpy as np -fig = figure() -ax1 = fig.add_subplot(221) -ax2 = fig.add_subplot(222) -ax3 = fig.add_subplot(223) -ax4 = fig.add_subplot(224) +fig, axs = plt.subplots(2, 2) +ax1 = axs[0, 0] +ax2 = axs[0, 1] +ax3 = axs[1, 0] +ax4 = axs[1, 1] x = np.random.randn(20, 20) -x[5] = 0. +x[5, :] = 0. x[:, 12] = 0. ax1.spy(x, markersize=5) @@ -25,4 +25,4 @@ ax3.spy(x) ax4.spy(x, precision=0.1) -show() +plt.show() diff --git a/examples/pylab_examples/stackplot_demo.py b/examples/pylab_examples/stackplot_demo.py index 609c0d0c1902..a9dceac9b913 100644 --- a/examples/pylab_examples/stackplot_demo.py +++ b/examples/pylab_examples/stackplot_demo.py @@ -55,6 +55,6 @@ def bump(a): d = layers(3, 100) -plt.subplots() -plt.stackplot(range(100), d.T, baseline='wiggle') +fig, ax = plt.subplots() +ax.stackplot(range(100), d.T, baseline='wiggle') plt.show() diff --git a/examples/statistics/barchart_demo.py b/examples/statistics/barchart_demo.py index 42123185fb9b..e4ea9022806c 100644 --- a/examples/statistics/barchart_demo.py +++ b/examples/statistics/barchart_demo.py @@ -34,27 +34,24 @@ opacity = 0.4 error_config = {'ecolor': '0.3'} -rects1 = plt.bar(index, means_men, bar_width, - alpha=opacity, - color='b', - yerr=std_men, - error_kw=error_config, - label='Men') - -rects2 = plt.bar(index + bar_width, means_women, bar_width, - alpha=opacity, - color='r', - yerr=std_women, - error_kw=error_config, - label='Women') - -plt.xlabel('Group') -plt.ylabel('Scores') -plt.title('Scores by group and gender') -plt.xticks(index + bar_width / 2, ('A', 'B', 'C', 'D', 'E')) -plt.legend() - -plt.tight_layout() +rects1 = ax.bar(index, means_men, bar_width, + alpha=opacity, color='b', + yerr=std_men, error_kw=error_config, + label='Men') + +rects2 = ax.bar(index + bar_width, means_women, bar_width, + alpha=opacity, color='r', + yerr=std_women, error_kw=error_config, + label='Women') + +ax.set_xlabel('Group') +ax.set_ylabel('Scores') +ax.set_title('Scores by group and gender') +ax.set_xticks(index + bar_width / 2) +ax.set_xticklabels(('A', 'B', 'C', 'D', 'E')) +ax.legend() + +fig.tight_layout() plt.show() diff --git a/examples/statistics/boxplot_demo.py b/examples/statistics/boxplot_demo.py index b8893e5c81f3..aac441baa4f8 100644 --- a/examples/statistics/boxplot_demo.py +++ b/examples/statistics/boxplot_demo.py @@ -25,28 +25,34 @@ flier_low = np.random.rand(10) * -100 data = np.concatenate((spread, center, flier_high, flier_low), 0) +fig, axs = plt.subplots(2, 3) + # basic plot -plt.boxplot(data) +axs[0, 0].boxplot(data) +axs[0, 0].set_title('basic plot') # notched plot -plt.figure() -plt.boxplot(data, 1) +axs[0, 1].boxplot(data, 1) +axs[0, 1].set_title('notched plot') # change outlier point symbols -plt.figure() -plt.boxplot(data, 0, 'gD') +axs[0, 2].boxplot(data, 0, 'gD') +axs[0, 2].set_title('change outlier\npoint symbols') # don't show outlier points -plt.figure() -plt.boxplot(data, 0, '') +axs[1, 0].boxplot(data, 0, '') +axs[1, 0].set_title("don't show\noutlier points") # horizontal boxes -plt.figure() -plt.boxplot(data, 0, 'rs', 0) +axs[1, 1].boxplot(data, 0, 'rs', 0) +axs[1, 1].set_title('horizontal boxes') # change whisker length -plt.figure() -plt.boxplot(data, 0, 'rs', 0, 0.75) +axs[1, 2].boxplot(data, 0, 'rs', 0, 0.75) +axs[1, 2].set_title('change whisker length') + +fig.subplots_adjust(left=0.08, right=0.98, bottom=0.05, top=0.9, + hspace=0.4, wspace=0.3) # fake up some more data spread = np.random.rand(50) * 100 @@ -56,15 +62,15 @@ d2 = np.concatenate((spread, center, flier_high, flier_low), 0) data.shape = (-1, 1) d2.shape = (-1, 1) -# data = concatenate( (data, d2), 1 ) # Making a 2-D array only works if all the columns are the # same length. If they are not, then use a list instead. # This is actually more efficient because boxplot converts # a 2-D array into a list of vectors internally anyway. data = [data, d2, d2[::2, 0]] -# multiple box plots on one figure -plt.figure() -plt.boxplot(data) + +# Multiple box plots on one Axes +fig, ax = plt.subplots() +ax.boxplot(data) plt.show() @@ -101,9 +107,9 @@ fig, ax1 = plt.subplots(figsize=(10, 6)) fig.canvas.set_window_title('A Boxplot Example') -plt.subplots_adjust(left=0.075, right=0.95, top=0.9, bottom=0.25) +fig.subplots_adjust(left=0.075, right=0.95, top=0.9, bottom=0.25) -bp = plt.boxplot(data, notch=0, sym='+', vert=1, whis=1.5) +bp = ax1.boxplot(data, notch=0, sym='+', vert=1, whis=1.5) plt.setp(bp['boxes'], color='black') plt.setp(bp['whiskers'], color='black') plt.setp(bp['fliers'], color='red', marker='+') @@ -142,11 +148,11 @@ for j in range(2): medianX.append(med.get_xdata()[j]) medianY.append(med.get_ydata()[j]) - plt.plot(medianX, medianY, 'k') + ax1.plot(medianX, medianY, 'k') medians[i] = medianY[0] # Finally, overplot the sample averages, with horizontal alignment # in the center of each box - plt.plot([np.average(med.get_xdata())], [np.average(data[i])], + ax1.plot([np.average(med.get_xdata())], [np.average(data[i])], color='w', marker='*', markeredgecolor='k') # Set the axes ranges and axes labels @@ -154,8 +160,8 @@ top = 40 bottom = -5 ax1.set_ylim(bottom, top) -xtickNames = plt.setp(ax1, xticklabels=np.repeat(randomDists, 2)) -plt.setp(xtickNames, rotation=45, fontsize=8) +ax1.set_xticklabels(np.repeat(randomDists, 2), + rotation=45, fontsize=8) # Due to the Y-axis scale being different across samples, it can be # hard to compare differences in medians across the samples. Add upper @@ -171,16 +177,16 @@ color=boxColors[k]) # Finally, add a basic legend -plt.figtext(0.80, 0.08, str(N) + ' Random Numbers', - backgroundcolor=boxColors[0], color='black', weight='roman', - size='x-small') -plt.figtext(0.80, 0.045, 'IID Bootstrap Resample', - backgroundcolor=boxColors[1], - color='white', weight='roman', size='x-small') -plt.figtext(0.80, 0.015, '*', color='white', backgroundcolor='silver', - weight='roman', size='medium') -plt.figtext(0.815, 0.013, ' Average Value', color='black', weight='roman', - size='x-small') +fig.text(0.80, 0.08, str(N) + ' Random Numbers', + backgroundcolor=boxColors[0], color='black', weight='roman', + size='x-small') +fig.text(0.80, 0.045, 'IID Bootstrap Resample', + backgroundcolor=boxColors[1], + color='white', weight='roman', size='x-small') +fig.text(0.80, 0.015, '*', color='white', backgroundcolor='silver', + weight='roman', size='medium') +fig.text(0.815, 0.013, ' Average Value', color='black', weight='roman', + size='x-small') plt.show() diff --git a/examples/statistics/hexbin_demo.py b/examples/statistics/hexbin_demo.py index 70333d88b772..33446d686549 100644 --- a/examples/statistics/hexbin_demo.py +++ b/examples/statistics/hexbin_demo.py @@ -79,18 +79,17 @@ gridsize = 30 -plt.subplot(211) -plt.hexbin(x, y, C=z, gridsize=gridsize, marginals=True, cmap=plt.cm.RdBu, - vmax=abs(z).max(), vmin=-abs(z).max()) -plt.axis([xmin, xmax, ymin, ymax]) -cb = plt.colorbar() -cb.set_label('mean value') +fig, (ax0, ax1) = plt.subplots(2, 1) +c = ax0.hexbin(x, y, C=z, gridsize=gridsize, marginals=True, cmap=plt.cm.RdBu, + vmax=abs(z).max(), vmin=-abs(z).max()) +ax0.axis([xmin, xmax, ymin, ymax]) +cb = fig.colorbar(c, ax=ax0) +cb.set_label('mean value') -plt.subplot(212) -plt.hexbin(x, y, gridsize=gridsize, cmap=plt.cm.Blues_r) -plt.axis([xmin, xmax, ymin, ymax]) -cb = plt.colorbar() +c = ax1.hexbin(x, y, gridsize=gridsize, cmap=plt.cm.Blues_r) +ax1.axis([xmin, xmax, ymin, ymax]) +cb = fig.colorbar(c, ax=ax1) cb.set_label('N observations') plt.show() diff --git a/examples/subplots_axes_and_figures/subplot_toolbar.py b/examples/subplots_axes_and_figures/subplot_toolbar.py index 343a35bdfb2b..dcaa6d8927fb 100644 --- a/examples/subplots_axes_and_figures/subplot_toolbar.py +++ b/examples/subplots_axes_and_figures/subplot_toolbar.py @@ -7,15 +7,15 @@ import matplotlib.pyplot as plt import numpy as np -fig = plt.figure() -plt.subplot(221) -plt.imshow(np.random.random((100, 100))) -plt.subplot(222) -plt.imshow(np.random.random((100, 100))) -plt.subplot(223) -plt.imshow(np.random.random((100, 100))) -plt.subplot(224) -plt.imshow(np.random.random((100, 100))) +fig, axs = plt.subplots(2, 2) + +axs[0, 0].imshow(np.random.random((100, 100))) + +axs[0, 1].imshow(np.random.random((100, 100))) + +axs[1, 0].imshow(np.random.random((100, 100))) + +axs[1, 1].imshow(np.random.random((100, 100))) plt.subplot_tool() plt.show() diff --git a/examples/text_labels_and_annotations/legend_demo.py b/examples/text_labels_and_annotations/legend_demo.py index 2e42e36e0022..77db192ebe85 100644 --- a/examples/text_labels_and_annotations/legend_demo.py +++ b/examples/text_labels_and_annotations/legend_demo.py @@ -23,17 +23,19 @@ t1 = np.arange(0.0, 2.0, 0.1) t2 = np.arange(0.0, 2.0, 0.01) +fig, ax = plt.subplots() + # note that plot returns a list of lines. The "l1, = plot" usage # extracts the first element of the list into l1 using tuple # unpacking. So l1 is a Line2D instance, not a sequence of lines -l1, = plt.plot(t2, np.exp(-t2)) -l2, l3 = plt.plot(t2, np.sin(2 * np.pi * t2), '--o', t1, np.log(1 + t1), '.') -l4, = plt.plot(t2, np.exp(-t2) * np.sin(2 * np.pi * t2), 's-.') - -plt.legend((l2, l4), ('oscillatory', 'damped'), loc='upper right', shadow=True) -plt.xlabel('time') -plt.ylabel('volts') -plt.title('Damped oscillation') +l1, = ax.plot(t2, np.exp(-t2)) +l2, l3 = ax.plot(t2, np.sin(2 * np.pi * t2), '--o', t1, np.log(1 + t1), '.') +l4, = ax.plot(t2, np.exp(-t2) * np.sin(2 * np.pi * t2), 's-.') + +ax.legend((l2, l4), ('oscillatory', 'damped'), loc='upper right', shadow=True) +ax.set_xlabel('time') +ax.set_ylabel('volts') +ax.set_title('Damped oscillation') plt.show() @@ -42,21 +44,21 @@ x = np.linspace(0, 1) +fig, (ax0, ax1) = plt.subplots(2, 1) + # Plot the lines y=x**n for n=1..4. -ax = plt.subplot(2, 1, 1) for n in range(1, 5): - plt.plot(x, x**n, label="n={0}".format(n)) -plt.legend(loc="upper left", bbox_to_anchor=[0, 1], - ncol=2, shadow=True, title="Legend", fancybox=True) -ax.get_legend().get_title().set_color("red") + ax0.plot(x, x**n, label="n={0}".format(n)) +leg = ax0.legend(loc="upper left", bbox_to_anchor=[0, 1], + ncol=2, shadow=True, title="Legend", fancybox=True) +leg.get_title().set_color("red") # Demonstrate some more complex labels. -ax = plt.subplot(2, 1, 2) -plt.plot(x, x**2, label="multi\nline") +ax1.plot(x, x**2, label="multi\nline") half_pi = np.linspace(0, np.pi / 2) -plt.plot(np.sin(half_pi), np.cos(half_pi), label=r"$\frac{1}{2}\pi$") -plt.plot(x, 2**(x**2), label="$2^{x^2}$") -plt.legend(shadow=True, fancybox=True) +ax1.plot(np.sin(half_pi), np.cos(half_pi), label=r"$\frac{1}{2}\pi$") +ax1.plot(x, 2**(x**2), label="$2^{x^2}$") +ax1.legend(shadow=True, fancybox=True) plt.show() @@ -166,12 +168,12 @@ def create_artists(self, legend, orig_handle, x = np.linspace(0, 5, 100) -plt.figure() +fig, ax = plt.subplots() colors = plt.rcParams['axes.prop_cycle'].by_key()['color'][:5] styles = ['solid', 'dashed', 'dashed', 'dashed', 'solid'] lines = [] for i, color, style in zip(range(5), colors, styles): - plt.plot(x, np.sin(x) - .1 * i, c=color, ls=style) + ax.plot(x, np.sin(x) - .1 * i, c=color, ls=style) # make proxy artists @@ -180,7 +182,7 @@ def create_artists(self, legend, orig_handle, # set up the proxy artist lc = mcol.LineCollection(5 * line, linestyles=styles, colors=colors) # create the legend -plt.legend([lc], ['multi-line'], handler_map={type(lc): HandlerDashedLines()}, - handlelength=2.5, handleheight=3) +ax.legend([lc], ['multi-line'], handler_map={type(lc): HandlerDashedLines()}, + handlelength=2.5, handleheight=3) plt.show()