diff --git a/examples/images_contours_and_fields/streamplot_demo_start_points.py b/examples/images_contours_and_fields/streamplot_demo_start_points.py index b41def0eb838..0868ecdfd09e 100644 --- a/examples/images_contours_and_fields/streamplot_demo_start_points.py +++ b/examples/images_contours_and_fields/streamplot_demo_start_points.py @@ -1,30 +1,26 @@ """ -Demo of the `streamplot` function. +Demo of the streamplot function with starting points. -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. +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 -X, Y = (np.linspace(-3, 3, 100), - np.linspace(-3, 3, 100)) - -U, V = np.mgrid[-3:3:100j, 0:0:100j] +Y, X = np.mgrid[-3:3:100j, -3:3:100j] +U = -1 - X**2 + Y +V = 1 + X - Y**2 -seed_points = np.array([[-2, 0, 1], [-2, 0, 1]]) +# 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]]) -fig0, ax0 = plt.subplots() -strm = ax0.streamplot(X, Y, U, V, color=U, linewidth=2, - cmap=plt.cm.autumn, start_points=seed_points.T) -fig0.colorbar(strm.lines) +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) -ax0.plot(seed_points[0], seed_points[1], 'bo') +ax.plot(seed_points[0], seed_points[1], 'bo') -ax0.axis((-3, 3, -3, 3)) +ax.axis((-3, 3, -3, 3)) plt.show()