matplotlib.pyplot.streamplot#

matplotlib.pyplot.streamplot(x,y,u,v,density=1,linewidth=None,color=None,cmap=None,norm=None,arrowsize=1,arrowstyle='-|>',minlength=0.1,transform=None,zorder=None,start_points=None,maxlength=4.0,integration_direction='both',broken_streamlines=True,*,integration_max_step_scale=1.0,integration_max_error_scale=1.0,num_arrows=1,data=None)[source]#

Draw streamlines of a vector flow.

Parameters:
x, y1D/2D arrays

Evenly spaced strictly increasing arrays to make a grid. If 2D, allrows ofx must be equal and all columns ofy must be equal; i.e.,they must be as if generated bynp.meshgrid(x_1d,y_1d).

u, v2D arrays

x andy-velocities. The number of rows and columns must matchthe length ofy andx, respectively.

densityfloat or (float, float)

Controls the closeness of streamlines. Whendensity=1, the domainis divided into a 30x30 grid.density linearly scales this grid.Each cell in the grid can have, at most, one traversing streamline.For different densities in each direction, use a tuple(density_x, density_y).

linewidthfloat or 2D array

The width of the streamlines. With a 2D array the line width can bevaried across the grid. The array must have the same shape asuandv.

colorcolor or 2D array

The streamline color. If given an array, its values are converted tocolors usingcmap andnorm. The array must have the same shapeasu andv.

cmap, norm

Data normalization and colormapping parameters forcolor; only usedifcolor is an array of floats. Seeimshow for a detaileddescription.

arrowsizefloat

Scaling factor for the arrow size.

arrowstylestr

Arrow style specification.SeeFancyArrowPatch.

minlengthfloat

Minimum length of streamline in axes coordinates.

start_points(N, 2) array

Coordinates of starting points for the streamlines in data coordinates(the same coordinates as thex andy arrays).

zorderfloat

The zorder of the streamlines and arrows.Artists with lower zorder values are drawn first.

maxlengthfloat

Maximum length of streamline in axes coordinates.

integration_direction{'forward', 'backward', 'both'}, default: 'both'

Integrate the streamline in forward, backward or both directions.

dataindexable object, optional

If given, the following parameters also accept a strings, which isinterpreted asdata[s] ifs is a key indata:

x,y,u,v,start_points

broken_streamlinesboolean, default: True

If False, forces streamlines to continue until theyleave the plot domain. If True, they may be terminated if theycome too close to another streamline.

integration_max_step_scalefloat, default: 1.0

Multiplier on the maximum allowable step in the streamline integration routine.A value between zero and one results in a max integration step smaller thanthe default max step, resulting in more accurate streamlines at the costof greater computation time; a value greater than one does the converse. Must begreater than zero.

Added in version 3.11.

integration_max_error_scalefloat, default: 1.0

Multiplier on the maximum allowable error in the streamline integration routine.A value between zero and one results in a tighter max integration error thanthe default max error, resulting in more accurate streamlines at the costof greater computation time; a value greater than one does the converse. Must begreater than zero.

Added in version 3.11.

num_arrowsint

Number of arrows per streamline. The arrows are spaced equally along the stepseach streamline takes. Note that this can be different to being spaced equallyalong the distance of the streamline.

Returns:
StreamplotSet

Container object with attributes

This container will probably change in the future to allow changesto the colormap, alpha, etc. for both lines and arrows, but thesechanges should be backward compatible.

Notes

Examples usingmatplotlib.pyplot.streamplot#

Streamplot

Streamplot