From 08b238247ebccccb037198e021012e39655ee521 Mon Sep 17 00:00:00 2001 From: Tom McClintock Date: Wed, 15 Feb 2017 09:40:12 -0800 Subject: [PATCH 1/5] Merged the three streamplot_demo_X.py files into a single streamplot_demo.py file. Corrected the incorrect description that accompanied the start_points demo in the streamplot example. --- .../streamplot_demo.py | 68 +++++++++++++++++++ .../streamplot_demo_features.py | 33 --------- .../streamplot_demo_masking.py | 29 -------- .../streamplot_demo_start_points.py | 28 -------- 4 files changed, 68 insertions(+), 90 deletions(-) create mode 100644 examples/images_contours_and_fields/streamplot_demo.py delete mode 100644 examples/images_contours_and_fields/streamplot_demo_features.py delete mode 100644 examples/images_contours_and_fields/streamplot_demo_masking.py delete mode 100644 examples/images_contours_and_fields/streamplot_demo_start_points.py diff --git a/examples/images_contours_and_fields/streamplot_demo.py b/examples/images_contours_and_fields/streamplot_demo.py new file mode 100644 index 000000000000..812e53f892e7 --- /dev/null +++ b/examples/images_contours_and_fields/streamplot_demo.py @@ -0,0 +1,68 @@ +""" +========== +Streamplot +========== + +Demo of the `streamplot` function. + +A streamplot, or streamline plot, is used to display 2D vector fields. This +example shows a few features of the stream plot function: + + * Varying the color along a streamline. + * Varying the density of streamlines. + * Varying the line width along a stream line. + * Streamlines skipping masked regions and NaN values. + * Controlling the start points of streamlines. +""" +import numpy as np +import matplotlib.pyplot as plt + +w = 3 +Y, X = np.mgrid[-w:w:100j, -w:w:100j] +U = -1 - X**2 + Y +V = 1 + X - Y**2 +speed = np.sqrt(U*U + V*V) + +# Varying color along a streamline +fig0, ax = plt.subplots() +strm = ax.streamplot(X, Y, U, V, color=U, linewidth=2, cmap=plt.cm.autumn) +fig0.colorbar(strm.lines) + +# Varying the density of streamlines +fig1, (ax1, ax2) = plt.subplots(ncols=2) +ax1.streamplot(X, Y, U, V, density=[0.5, 1]) + +# Varying the line width along a stream line +lw = 5*speed / speed.max() +ax2.streamplot(X, Y, U, V, density=0.6, color='k', linewidth=lw) + +# Streamlines skipping masked regions and NaN values +mask = np.zeros(U.shape, dtype=bool) +mask[40:60, 40:60] = True +U[:20, :20] = np.nan +U = np.ma.array(U, mask=mask) + +fig2, ax = plt.subplots() +ax.streamplot(X, Y, U, V, color='r') + +ax.imshow(-mask, extent=(-w, w, -w, w), alpha=0.5, + interpolation='nearest', cmap=plt.cm.gray) + +# Controlling the start points of streamlines +X, Y = (np.linspace(-3, 3, 100), + np.linspace(-3, 3, 100)) + +U, V = np.mgrid[-3:3:100j, 0:0:100j] + +seed_points = np.array([[-2, 0, 1], [-2, 0, 1]]) + +fig4, ax = plt.subplots() +strm = ax.streamplot(X, Y, U, V, color=U, linewidth=2, + cmap=plt.cm.autumn, start_points=seed_points.T) +fig4.colorbar(strm.lines) + +ax.plot(seed_points[0], seed_points[1],'bo') + +ax.axis((-3, 3, -3, 3)) + +plt.show() diff --git a/examples/images_contours_and_fields/streamplot_demo_features.py b/examples/images_contours_and_fields/streamplot_demo_features.py deleted file mode 100644 index c9e520689fa1..000000000000 --- a/examples/images_contours_and_fields/streamplot_demo_features.py +++ /dev/null @@ -1,33 +0,0 @@ -""" -========== -Streamplot -========== - -Demo of the `streamplot` function. - -A streamplot, or streamline plot, is used to display 2D vector fields. This -example shows a few features of the stream plot function: - - * Varying the color along a streamline. - * Varying the density of streamlines. - * Varying the line width along a stream line. -""" -import numpy as np -import matplotlib.pyplot as plt - -Y, X = np.mgrid[-3:3:100j, -3:3:100j] -U = -1 - X**2 + Y -V = 1 + X - Y**2 -speed = np.sqrt(U*U + V*V) - -fig0, ax0 = plt.subplots() -strm = ax0.streamplot(X, Y, U, V, color=U, linewidth=2, cmap=plt.cm.autumn) -fig0.colorbar(strm.lines) - -fig1, (ax1, ax2) = plt.subplots(ncols=2) -ax1.streamplot(X, Y, U, V, density=[0.5, 1]) - -lw = 5*speed / speed.max() -ax2.streamplot(X, Y, U, V, density=0.6, color='k', linewidth=lw) - -plt.show() diff --git a/examples/images_contours_and_fields/streamplot_demo_masking.py b/examples/images_contours_and_fields/streamplot_demo_masking.py deleted file mode 100644 index d1354fe7c9c3..000000000000 --- a/examples/images_contours_and_fields/streamplot_demo_masking.py +++ /dev/null @@ -1,29 +0,0 @@ -""" -================================ -Streamplot function with masking -================================ - -This example shows how streamlines created by the streamplot function skips -masked regions and NaN values. -""" -import numpy as np -import matplotlib.pyplot as plt - -w = 3 -Y, X = np.mgrid[-w:w:100j, -w:w:100j] -U = -1 - X**2 + Y -V = 1 + X - Y**2 -speed = np.sqrt(U*U + V*V) - -mask = np.zeros(U.shape, dtype=bool) -mask[40:60, 40:60] = True -U[:20, :20] = np.nan -U = np.ma.array(U, mask=mask) - -fig, ax = plt.subplots() -ax.streamplot(X, Y, U, V, color='r') - -ax.imshow(~mask, extent=(-w, w, -w, w), alpha=0.5, - interpolation='nearest', cmap=plt.cm.gray) - -plt.show() diff --git a/examples/images_contours_and_fields/streamplot_demo_start_points.py b/examples/images_contours_and_fields/streamplot_demo_start_points.py deleted file mode 100644 index 22f5bdba82db..000000000000 --- a/examples/images_contours_and_fields/streamplot_demo_start_points.py +++ /dev/null @@ -1,28 +0,0 @@ -""" -======================================== -Streamplot function with starting points -======================================== - -This example shows how to fix the streamlines that are plotted, by passing -an array of seed points to the `start_points` keyword argument. -""" -import numpy as np -import matplotlib.pyplot as plt - -Y, X = np.mgrid[-3:3:100j, -3:3:100j] -U = -1 - X**2 + Y -V = 1 + X - Y**2 - -# 5 points along the first diagonal and a point in the left upper quadrant -seed_points = np.array([[-2, -1, 0, 1, 2, -1], [-2, -1, 0, 1, 2, 2]]) - -fig, ax = plt.subplots() -strm = ax.streamplot(X, Y, U, V, color=U, linewidth=2, - cmap=plt.cm.autumn, start_points=seed_points.T) -fig.colorbar(strm.lines) - -ax.plot(seed_points[0], seed_points[1], 'bo') - -ax.axis((-3, 3, -3, 3)) - -plt.show() From 4618736d1fcd8f7f053eac580d3939c17a27d9d4 Mon Sep 17 00:00:00 2001 From: Tom McClintock Date: Wed, 15 Feb 2017 10:17:30 -0800 Subject: [PATCH 2/5] Changed plt.cm.autumn to the string autumn when specifying the colormaps. --- examples/images_contours_and_fields/streamplot_demo.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/images_contours_and_fields/streamplot_demo.py b/examples/images_contours_and_fields/streamplot_demo.py index 812e53f892e7..546d262b82ba 100644 --- a/examples/images_contours_and_fields/streamplot_demo.py +++ b/examples/images_contours_and_fields/streamplot_demo.py @@ -25,7 +25,7 @@ # Varying color along a streamline fig0, ax = plt.subplots() -strm = ax.streamplot(X, Y, U, V, color=U, linewidth=2, cmap=plt.cm.autumn) +strm = ax.streamplot(X, Y, U, V, color=U, linewidth=2, cmap='autumn') fig0.colorbar(strm.lines) # Varying the density of streamlines @@ -58,7 +58,7 @@ fig4, ax = plt.subplots() strm = ax.streamplot(X, Y, U, V, color=U, linewidth=2, - cmap=plt.cm.autumn, start_points=seed_points.T) + cmap="autumn", start_points=seed_points.T) fig4.colorbar(strm.lines) ax.plot(seed_points[0], seed_points[1],'bo') From fadc12c4516de093fe1e0ccba05e21088281760b Mon Sep 17 00:00:00 2001 From: Tom McClintock Date: Thu, 16 Feb 2017 16:15:28 -0800 Subject: [PATCH 3/5] Changed fig4 to fig3... because there was no fig3. --- examples/images_contours_and_fields/streamplot_demo.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/images_contours_and_fields/streamplot_demo.py b/examples/images_contours_and_fields/streamplot_demo.py index 546d262b82ba..534c3283ae1c 100644 --- a/examples/images_contours_and_fields/streamplot_demo.py +++ b/examples/images_contours_and_fields/streamplot_demo.py @@ -56,10 +56,10 @@ seed_points = np.array([[-2, 0, 1], [-2, 0, 1]]) -fig4, ax = plt.subplots() +fig3, ax = plt.subplots() strm = ax.streamplot(X, Y, U, V, color=U, linewidth=2, cmap="autumn", start_points=seed_points.T) -fig4.colorbar(strm.lines) +fig3.colorbar(strm.lines) ax.plot(seed_points[0], seed_points[1],'bo') From 2d8f334c932d9edc1c0efb5a4f3adaa207c40195 Mon Sep 17 00:00:00 2001 From: Tom McClintock Date: Thu, 16 Feb 2017 16:16:47 -0800 Subject: [PATCH 4/5] Added a space to conform to PEP8. --- examples/images_contours_and_fields/streamplot_demo.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/images_contours_and_fields/streamplot_demo.py b/examples/images_contours_and_fields/streamplot_demo.py index 534c3283ae1c..d1c981651807 100644 --- a/examples/images_contours_and_fields/streamplot_demo.py +++ b/examples/images_contours_and_fields/streamplot_demo.py @@ -61,7 +61,7 @@ cmap="autumn", start_points=seed_points.T) fig3.colorbar(strm.lines) -ax.plot(seed_points[0], seed_points[1],'bo') +ax.plot(seed_points[0], seed_points[1], 'bo') ax.axis((-3, 3, -3, 3)) From fc0ce67b442dcb6d916b544682224f57a8a30518 Mon Sep 17 00:00:00 2001 From: Tom McClintock Date: Sat, 18 Feb 2017 21:40:08 -0800 Subject: [PATCH 5/5] Fixed both references to the streamplot demo in the documentation files. --- doc/users/prev_whats_new/whats_new_1.2.rst | 2 +- doc/users/screenshots.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/users/prev_whats_new/whats_new_1.2.rst b/doc/users/prev_whats_new/whats_new_1.2.rst index 7f64c1e724c1..3e05807cf103 100644 --- a/doc/users/prev_whats_new/whats_new_1.2.rst +++ b/doc/users/prev_whats_new/whats_new_1.2.rst @@ -152,7 +152,7 @@ In addition to simply plotting the streamlines of the vector field, line widths of the streamlines to a separate parameter, such as the speed or local intensity of the vector field. -.. plot:: mpl_examples/images_contours_and_fields/streamplot_demo_features.py +.. plot:: mpl_examples/images_contours_and_fields/streamplot_demo.py New hist functionality diff --git a/doc/users/screenshots.rst b/doc/users/screenshots.rst index 7bf30859f87e..df07cb2ff064 100644 --- a/doc/users/screenshots.rst +++ b/doc/users/screenshots.rst @@ -71,7 +71,7 @@ a vector field. In addition to simply plotting the streamlines, it allows you to map the colors and/or line widths of streamlines to a separate parameter, such as the speed or local intensity of the vector field. -.. plot:: mpl_examples/images_contours_and_fields/streamplot_demo_features.py +.. plot:: mpl_examples/images_contours_and_fields/streamplot_demo.py This feature complements the :meth:`~matplotlib.pyplot.quiver` function for plotting vector fields. Thanks to Tom Flannaghan and Tony Yu for adding the