Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 14 additions & 18 deletions examples/images_contours_and_fields/streamplot_demo_start_points.py
Original file line number Diff line number Diff line change
@@ -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()