from turtle import color
import matplotlib.pyplot as plt
import numpy as np
from mpl_toolkits.mplot3d import Axes3D
plt.style.use('seaborn-darkgrid')
# make a stream function:
X, Y = np.meshgrid(np.linspace(-3, 3, 256), np.linspace(-3, 3, 256))
Z = (1 - X/2 + X**5 + Y**3) * np.exp(-X**2 - Y**2)
# make U and V out of the streamfunction:
V = np.diff(Z[1:, :], axis=1)
U = -np.diff(Z[:, 1:], axis=0)
# plot:
fig, ax = plt.subplots()
ax.streamplot(X[1:, 1:], Y[1:, 1:],U, V,color = U,cmap='Accent')
plt.show()
ax.streamplot(X[1:, 1:], Y[1:, 1:],U, V,color = V,cmap='Accent')
ax.streamplot(X[1:, 1:], Y[1:, 1:],U, V,color = U,cmap='Accent_r')
ax.streamplot(X[1:, 1:], Y[1:, 1:],U, V,color = U,cmap='Paired')
ax.streamplot(X[1:, 1:], Y[1:, 1:],U, V,color = U,cmap='Paired_r')
ax.streamplot(X[1:, 1:], Y[1:, 1:],U, V,color = U,cmap='BrBG')
ax.streamplot(X[1:, 1:], Y[1:, 1:],U, V,color = U,cmap='BrBG_r')
ax.streamplot(X[1:, 1:], Y[1:, 1:],U, V,color = U,cmap='BuGn')
参考文献:https://vimsky.com/examples/usage/matplotlib-pyplot-streamplot-in-python.html
https://matplotlib.org/stable/plot_types/arrays/streamplot.html#sphx-glr-plot-types-arrays-streamplot-py