From d70af4c40d4f81c98e34b834f706ef73ae4fb4b5 Mon Sep 17 00:00:00 2001 From: David Stansby Date: Tue, 16 May 2017 18:50:42 +0100 Subject: [PATCH 1/2] Move some pylab examples to other folders PEP8 moved examples Move subplots and scatter examples PEP8 scatter examples Small example fixes Remove old barchart demos Add new barchart demo back --- .../animation_demo.py | 0 .../{pylab_examples => color}/color_by_yvalue.py | 11 ++++++----- examples/{pylab_examples => color}/color_demo.py | 15 ++++++++------- .../colours_sgskip.py => color/colors_sgskip.py} | 0 .../contour_corner_mask.py | 4 ++-- .../broken_barh.py | 0 .../scatter_custom_symbol.py | 11 +++++------ .../scatter_demo2.py | 2 +- .../scatter_hist.py | 0 .../scatter_masked.py | 12 ++++++------ .../scatter_profile.py | 6 +++--- .../scatter_star_poly.py | 2 +- .../scatter_symbol.py | 0 examples/pylab_examples/README | 13 ------------- examples/pylab_examples/barb_demo.py | 12 ++++++------ .../subplot_demo.py | 0 .../subplot_toolbar.py | 0 .../subplots_adjust.py | 0 .../subplots_demo.py | 0 19 files changed, 38 insertions(+), 50 deletions(-) rename examples/{pylab_examples => animation}/animation_demo.py (100%) rename examples/{pylab_examples => color}/color_by_yvalue.py (71%) rename examples/{pylab_examples => color}/color_demo.py (68%) rename examples/{pylab_examples/colours_sgskip.py => color/colors_sgskip.py} (100%) rename examples/{pylab_examples => images_contours_and_fields}/contour_corner_mask.py (92%) rename examples/{pylab_examples => lines_bars_and_markers}/broken_barh.py (100%) rename examples/{pylab_examples => lines_bars_and_markers}/scatter_custom_symbol.py (53%) rename examples/{pylab_examples => lines_bars_and_markers}/scatter_demo2.py (94%) rename examples/{pylab_examples => lines_bars_and_markers}/scatter_hist.py (100%) rename examples/{pylab_examples => lines_bars_and_markers}/scatter_masked.py (64%) rename examples/{pylab_examples => lines_bars_and_markers}/scatter_profile.py (89%) rename examples/{pylab_examples => lines_bars_and_markers}/scatter_star_poly.py (92%) rename examples/{pylab_examples => lines_bars_and_markers}/scatter_symbol.py (100%) delete mode 100644 examples/pylab_examples/README rename examples/{pylab_examples => subplots_axes_and_figures}/subplot_demo.py (100%) rename examples/{pylab_examples => subplots_axes_and_figures}/subplot_toolbar.py (100%) rename examples/{pylab_examples => subplots_axes_and_figures}/subplots_adjust.py (100%) rename examples/{pylab_examples => subplots_axes_and_figures}/subplots_demo.py (100%) diff --git a/examples/pylab_examples/animation_demo.py b/examples/animation/animation_demo.py similarity index 100% rename from examples/pylab_examples/animation_demo.py rename to examples/animation/animation_demo.py diff --git a/examples/pylab_examples/color_by_yvalue.py b/examples/color/color_by_yvalue.py similarity index 71% rename from examples/pylab_examples/color_by_yvalue.py rename to examples/color/color_by_yvalue.py index 0af7748ca172..26ffbd95091d 100644 --- a/examples/pylab_examples/color_by_yvalue.py +++ b/examples/color/color_by_yvalue.py @@ -1,7 +1,7 @@ """ -=============== -Color By Yvalue -=============== +================ +Color By y-value +================ Use masked arrays to plot a line with different colors by y-value. """ @@ -9,7 +9,7 @@ import matplotlib.pyplot as plt t = np.arange(0.0, 2.0, 0.01) -s = np.sin(2*np.pi*t) +s = np.sin(2 * np.pi * t) upper = 0.77 lower = -0.77 @@ -19,5 +19,6 @@ slower = np.ma.masked_where(s > lower, s) smiddle = np.ma.masked_where(np.logical_or(s < lower, s > upper), s) -plt.plot(t, smiddle, t, slower, t, supper) +fig, ax = plt.subplots() +ax.plot(t, smiddle, t, slower, t, supper) plt.show() diff --git a/examples/pylab_examples/color_demo.py b/examples/color/color_demo.py similarity index 68% rename from examples/pylab_examples/color_demo.py rename to examples/color/color_demo.py index 4abbc41829b4..684e4a8ddd8c 100644 --- a/examples/pylab_examples/color_demo.py +++ b/examples/color/color_demo.py @@ -22,12 +22,13 @@ import matplotlib.pyplot as plt import numpy as np -plt.subplot(111, facecolor='darkslategray') -#subplot(111, facecolor='#ababab') t = np.arange(0.0, 2.0, 0.01) -s = np.sin(2*np.pi*t) -plt.plot(t, s, 'C1') -plt.xlabel('time (s)', color='C1') -plt.ylabel('voltage (mV)', color='0.5') # grayscale color -plt.title('About as silly as it gets, folks', color='#afeeee') +s = np.sin(2 * np.pi * t) + +fig, ax = plt.subplots(facecolor='darkslategray') +ax.plot(t, s, 'C1') +ax.set_xlabel('time (s)', color='C1') +ax.set_ylabel('voltage (mV)', color='0.5') # grayscale color +ax.set_title('About as silly as it gets, folks', color='#afeeee') + plt.show() diff --git a/examples/pylab_examples/colours_sgskip.py b/examples/color/colors_sgskip.py similarity index 100% rename from examples/pylab_examples/colours_sgskip.py rename to examples/color/colors_sgskip.py diff --git a/examples/pylab_examples/contour_corner_mask.py b/examples/images_contours_and_fields/contour_corner_mask.py similarity index 92% rename from examples/pylab_examples/contour_corner_mask.py rename to examples/images_contours_and_fields/contour_corner_mask.py index cae702c23e44..c879004e18a3 100644 --- a/examples/pylab_examples/contour_corner_mask.py +++ b/examples/images_contours_and_fields/contour_corner_mask.py @@ -11,7 +11,7 @@ # Data to plot. x, y = np.meshgrid(np.arange(7), np.arange(10)) -z = np.sin(0.5*x)*np.cos(0.52*y) +z = np.sin(0.5 * x) * np.cos(0.52 * y) # Mask various z values. mask = np.zeros_like(z, dtype=np.bool) @@ -24,7 +24,7 @@ corner_masks = [False, True] for i, corner_mask in enumerate(corner_masks): - plt.subplot(1, 2, i+1) + plt.subplot(1, 2, i + 1) cs = plt.contourf(x, y, z, corner_mask=corner_mask) plt.contour(cs, colors='k') plt.title('corner_mask = {0}'.format(corner_mask)) diff --git a/examples/pylab_examples/broken_barh.py b/examples/lines_bars_and_markers/broken_barh.py similarity index 100% rename from examples/pylab_examples/broken_barh.py rename to examples/lines_bars_and_markers/broken_barh.py diff --git a/examples/pylab_examples/scatter_custom_symbol.py b/examples/lines_bars_and_markers/scatter_custom_symbol.py similarity index 53% rename from examples/pylab_examples/scatter_custom_symbol.py rename to examples/lines_bars_and_markers/scatter_custom_symbol.py index 4c333eb437d9..5c155393a276 100644 --- a/examples/pylab_examples/scatter_custom_symbol.py +++ b/examples/lines_bars_and_markers/scatter_custom_symbol.py @@ -5,16 +5,15 @@ """ import matplotlib.pyplot as plt -from numpy import arange, pi, cos, sin -from numpy.random import rand +import numpy as np # unit area ellipse rx, ry = 3., 1. -area = rx * ry * pi -theta = arange(0, 2*pi + 0.01, 0.1) -verts = list(zip(rx/area*cos(theta), ry/area*sin(theta))) +area = rx * ry * np.pi +theta = np.arange(0, 2 * np.pi + 0.01, 0.1) +verts = list(zip(rx / area * np.cos(theta), ry / area * np.sin(theta))) -x, y, s, c = rand(4, 30) +x, y, s, c = np.random.rand(4, 30) s *= 10**2. fig, ax = plt.subplots() diff --git a/examples/pylab_examples/scatter_demo2.py b/examples/lines_bars_and_markers/scatter_demo2.py similarity index 94% rename from examples/pylab_examples/scatter_demo2.py rename to examples/lines_bars_and_markers/scatter_demo2.py index 52a3693d3812..da7d8433a012 100644 --- a/examples/pylab_examples/scatter_demo2.py +++ b/examples/lines_bars_and_markers/scatter_demo2.py @@ -16,7 +16,7 @@ price_data = np.load(datafile)['price_data'].view(np.recarray) price_data = price_data[-250:] # get the most recent 250 trading days -delta1 = np.diff(price_data.adj_close)/price_data.adj_close[:-1] +delta1 = np.diff(price_data.adj_close) / price_data.adj_close[:-1] # Marker size in units of points^2 volume = (15 * price_data.volume[:-2] / price_data.volume[0])**2 diff --git a/examples/pylab_examples/scatter_hist.py b/examples/lines_bars_and_markers/scatter_hist.py similarity index 100% rename from examples/pylab_examples/scatter_hist.py rename to examples/lines_bars_and_markers/scatter_hist.py diff --git a/examples/pylab_examples/scatter_masked.py b/examples/lines_bars_and_markers/scatter_masked.py similarity index 64% rename from examples/pylab_examples/scatter_masked.py rename to examples/lines_bars_and_markers/scatter_masked.py index ddfd8b2b741b..56acfa2b6347 100644 --- a/examples/pylab_examples/scatter_masked.py +++ b/examples/lines_bars_and_markers/scatter_masked.py @@ -13,17 +13,17 @@ N = 100 r0 = 0.6 -x = 0.9*np.random.rand(N) -y = 0.9*np.random.rand(N) -area = np.pi*(10 * np.random.rand(N))**2 # 0 to 10 point radii +x = 0.9 * np.random.rand(N) +y = 0.9 * np.random.rand(N) +area = np.pi * (10 * np.random.rand(N))**2 # 0 to 10 point radii c = np.sqrt(area) -r = np.sqrt(x*x + y*y) +r = np.sqrt(x * x + y * y) area1 = np.ma.masked_where(r < r0, area) area2 = np.ma.masked_where(r >= r0, area) plt.scatter(x, y, s=area1, marker='^', c=c) plt.scatter(x, y, s=area2, marker='o', c=c) # Show the boundary between the regions: -theta = np.arange(0, np.pi/2, 0.01) -plt.plot(r0*np.cos(theta), r0*np.sin(theta)) +theta = np.arange(0, np.pi / 2, 0.01) +plt.plot(r0 * np.cos(theta), r0 * np.sin(theta)) plt.show() diff --git a/examples/pylab_examples/scatter_profile.py b/examples/lines_bars_and_markers/scatter_profile.py similarity index 89% rename from examples/pylab_examples/scatter_profile.py rename to examples/lines_bars_and_markers/scatter_profile.py index 09bc000101bd..9ac4dbcc69a4 100644 --- a/examples/pylab_examples/scatter_profile.py +++ b/examples/lines_bars_and_markers/scatter_profile.py @@ -29,8 +29,8 @@ for N in (20, 100, 1000, 10000, 50000): tstart = time.time() - x = 0.9*np.random.rand(N) - y = 0.9*np.random.rand(N) - s = 20*np.random.rand(N) + x = 0.9 * np.random.rand(N) + y = 0.9 * np.random.rand(N) + s = 20 * np.random.rand(N) plt.scatter(x, y, s) print('%d symbols in %1.2f s' % (N, time.time() - tstart)) diff --git a/examples/pylab_examples/scatter_star_poly.py b/examples/lines_bars_and_markers/scatter_star_poly.py similarity index 92% rename from examples/pylab_examples/scatter_star_poly.py rename to examples/lines_bars_and_markers/scatter_star_poly.py index 995ce6a8fd29..abadaf857d1f 100644 --- a/examples/pylab_examples/scatter_star_poly.py +++ b/examples/lines_bars_and_markers/scatter_star_poly.py @@ -25,7 +25,7 @@ plt.subplot(323) plt.scatter(x, y, s=80, c=z, marker=(verts, 0)) # equivalent: -#plt.scatter(x,y,s=80, c=z, marker=None, verts=verts) +# plt.scatter(x, y, s=80, c=z, marker=None, verts=verts) plt.subplot(324) plt.scatter(x, y, s=80, c=z, marker=(5, 1)) diff --git a/examples/pylab_examples/scatter_symbol.py b/examples/lines_bars_and_markers/scatter_symbol.py similarity index 100% rename from examples/pylab_examples/scatter_symbol.py rename to examples/lines_bars_and_markers/scatter_symbol.py diff --git a/examples/pylab_examples/README b/examples/pylab_examples/README deleted file mode 100644 index 1fbe320f0cc2..000000000000 --- a/examples/pylab_examples/README +++ /dev/null @@ -1,13 +0,0 @@ -Here are some demos of how to use the matplotlib. - - --- embedding_in_gtk - The Figure class derives from gtk.DrawingArea, - so it is easy to embed in larger applications. - --- histograms_gauss.py - 2D histograms; requires the jdh.mlab module - --- simple_plot.py - the basic 2D line plot - --- subplot_demo.py - how to do multiple axes on a single plot - --- vline_hline_demo.py - working with straight lines diff --git a/examples/pylab_examples/barb_demo.py b/examples/pylab_examples/barb_demo.py index 77a9790d7a8e..12ad4d727ab2 100644 --- a/examples/pylab_examples/barb_demo.py +++ b/examples/pylab_examples/barb_demo.py @@ -10,7 +10,7 @@ x = np.linspace(-5, 5, 5) X, Y = np.meshgrid(x, x) -U, V = 12*X, 12*Y +U, V = 12 * X, 12 * Y data = [(-1.5, .5, -6, -6), (1, -1, -46, 46), @@ -27,21 +27,21 @@ ax.barbs(X, Y, U, V) # Arbitrary set of vectors, make them longer and change the pivot point -#(point around which they're rotated) to be the middle +# (point around which they're rotated) to be the middle ax = plt.subplot(2, 2, 2) ax.barbs(data['x'], data['y'], data['u'], data['v'], length=8, pivot='middle') # Showing colormapping with uniform grid. Fill the circle for an empty barb, # don't round the values, and change some of the size parameters ax = plt.subplot(2, 2, 3) -ax.barbs(X, Y, U, V, np.sqrt(U*U + V*V), fill_empty=True, rounding=False, +ax.barbs(X, Y, U, V, np.sqrt(U * U + V * V), fill_empty=True, rounding=False, sizes=dict(emptybarb=0.25, spacing=0.2, height=0.3)) # Change colors as well as the increments for parts of the barbs ax = plt.subplot(2, 2, 4) ax.barbs(data['x'], data['y'], data['u'], data['v'], flagcolor='r', - barbcolor=['b', 'g'], barb_increments=dict(half=10, full=20, flag=100), - flip_barb=True) + barbcolor=['b', 'g'], + barb_increments=dict(half=10, full=20, flag=100), flip_barb=True) # Masked arrays are also supported masked_u = np.ma.masked_array(data['u']) @@ -49,7 +49,7 @@ masked_u[4] = np.ma.masked # Identical plot to panel 2 in the first figure, but with the point at -#(0.5, 0.25) missing (masked) +# (0.5, 0.25) missing (masked) fig2 = plt.figure() ax = fig2.add_subplot(1, 1, 1) ax.barbs(data['x'], data['y'], masked_u, data['v'], length=8, pivot='middle') diff --git a/examples/pylab_examples/subplot_demo.py b/examples/subplots_axes_and_figures/subplot_demo.py similarity index 100% rename from examples/pylab_examples/subplot_demo.py rename to examples/subplots_axes_and_figures/subplot_demo.py diff --git a/examples/pylab_examples/subplot_toolbar.py b/examples/subplots_axes_and_figures/subplot_toolbar.py similarity index 100% rename from examples/pylab_examples/subplot_toolbar.py rename to examples/subplots_axes_and_figures/subplot_toolbar.py diff --git a/examples/pylab_examples/subplots_adjust.py b/examples/subplots_axes_and_figures/subplots_adjust.py similarity index 100% rename from examples/pylab_examples/subplots_adjust.py rename to examples/subplots_axes_and_figures/subplots_adjust.py diff --git a/examples/pylab_examples/subplots_demo.py b/examples/subplots_axes_and_figures/subplots_demo.py similarity index 100% rename from examples/pylab_examples/subplots_demo.py rename to examples/subplots_axes_and_figures/subplots_demo.py From 28be3ce4a022fb7226bdfc1487277d96bdbcb271 Mon Sep 17 00:00:00 2001 From: David Stansby Date: Wed, 24 May 2017 13:18:03 +0100 Subject: [PATCH 2/2] Fix broken links --- doc/users/prev_whats_new/whats_new_1.0.rst | 5 +---- doc/users/prev_whats_new/whats_new_1.5.rst | 7 ++----- tutorials/01_introductory/pyplot.py | 2 +- tutorials/01_introductory/sample_plots.py | 4 ++-- 4 files changed, 6 insertions(+), 12 deletions(-) diff --git a/doc/users/prev_whats_new/whats_new_1.0.rst b/doc/users/prev_whats_new/whats_new_1.0.rst index 5b376298e7b6..aa2581fc5406 100644 --- a/doc/users/prev_whats_new/whats_new_1.0.rst +++ b/doc/users/prev_whats_new/whats_new_1.0.rst @@ -44,7 +44,7 @@ indexing (starts with 0). e.g.:: fig, axarr = plt.subplots(2, 2) axarr[0,0].plot([1,2,3]) # upper, left -See :ref:`sphx_glr_gallery_pylab_examples_subplot_demo.py` for several code examples. +See :ref:`sphx_glr_gallery_subplots_axes_and_figures_subplot_demo.py` for several code examples. Contour fixes and and triplot --------------------------------- @@ -147,6 +147,3 @@ Eric Firing went on a bug fixing and closing marathon, closing over `__ with help from Jae-Joon Lee, Michael Droettboom, Christoph Gohlke and Michiel de Hoon. - - - diff --git a/doc/users/prev_whats_new/whats_new_1.5.rst b/doc/users/prev_whats_new/whats_new_1.5.rst index 94f70d33047e..ec31bd887e0a 100644 --- a/doc/users/prev_whats_new/whats_new_1.5.rst +++ b/doc/users/prev_whats_new/whats_new_1.5.rst @@ -314,8 +314,8 @@ quads touching the point; any triangular corners comprising three unmasked points are contoured as usual. If the ``corner_mask`` keyword argument is not specified, the default value is taken from rcParams. -.. figure:: ../../gallery/pylab_examples/images/sphx_glr_contour_corner_mask_001.png - :target: ../../gallery/pylab_examples/contour_corner_mask.html +.. figure:: ../../gallery/images_contours_and_fields/images/sphx_glr_contour_corner_mask_001.png + :target: ../../gallery/images_contours_and_fields/contour_corner_mask.html :align: center :scale: 50 @@ -744,6 +744,3 @@ is important if your toolchain is prefixed. This is done in a simpilar way as setting `CC` or `CXX` before building. An example follows. export PKG_CONFIG=x86_64-pc-linux-gnu-pkg-config - - - diff --git a/tutorials/01_introductory/pyplot.py b/tutorials/01_introductory/pyplot.py index d849d29ca382..23f5604ed5ae 100644 --- a/tutorials/01_introductory/pyplot.py +++ b/tutorials/01_introductory/pyplot.py @@ -278,7 +278,7 @@ def f(t): # which allows you to specify the location as ``axes([left, bottom, # width, height])`` where all values are in fractional (0 to 1) # coordinates. See :ref:`sphx_glr_gallery_pylab_examples_axes_demo.py` for an example of -# placing axes manually and :ref:`sphx_glr_gallery_pylab_examples_subplot_demo.py` for an +# placing axes manually and :ref:`sphx_glr_gallery_subplots_axes_and_figures_subplot_demo.py` for an # example with lots of subplots. # # diff --git a/tutorials/01_introductory/sample_plots.py b/tutorials/01_introductory/sample_plots.py index 675b7a601dc9..c73279b24505 100644 --- a/tutorials/01_introductory/sample_plots.py +++ b/tutorials/01_introductory/sample_plots.py @@ -194,8 +194,8 @@ trading volume and colors varying with time. Here, the alpha attribute is used to make semitransparent circle markers. -.. figure:: ../../gallery/pylab_examples/images/sphx_glr_scatter_demo2_001.png - :target: ../../gallery/pylab_examples/scatter_demo2.html +.. figure:: ../../gallery/lines_bars_and_markers/images/sphx_glr_scatter_demo2_001.png + :target: ../../gallery/lines_bars_and_markers/scatter_demo2.html :align: center :scale: 50