Код: Выделить всё
import numpy as np
# model flow field
x = np.linspace(0, 2 * np.pi, 100)
y = np.linspace(0, 2 * np.pi, 100)
X, Y = np.meshgrid(x, y)
U = (np.cos(X) * np.sin(Y)) * np.exp(-X)
V = -np.sin(X) * np.cos(Y) * np.exp(-X)
Код: Выделить всё
import matplotlib.pyplot as plt
# Create a figure with axes
fig, ax1 = plt.subplots(1, 1, figsize=(3, 3))
mag = np.sqrt(U**2+V**2)
# Create a streamplot on the axis
lw = (mag/np.max(mag[10:,:]))
stream = ax1.streamplot(X, Y, U, V, linewidth=lw, arrowsize=1.5)
# Display the plots
plt.tight_layout()
plt.show()

Я изо всех сил старался получить обходной путь, поскольку функцияstreamplot изначально не поддерживает это, но мне это не удалось.
Я попробовал приведенное ниже, чтобы попытаться получить возвращаемые объекты из вызоваstreamplot, и каким-то образом напрямую перерисовать стрелки после изменения масштаба. Но этот код ничего не строит!
Код: Выделить всё
# Create a figure with axes
fig, ax = plt.subplots(1, 1, figsize=(3, 3))
# Access the arrow collection
arrow_coll = stream.arrows
line_coll = stream.lines
arrow_paths = arrow_coll.get_paths()
ax.add_collection(arrow_coll)
# Display the plots
plt.tight_layout()
plt.show()
Код: Выделить всё
# Create a figure with two axes
fig, ax = plt.subplots(1, 1, figsize=(3, 3))
# Access the arrow collection
arrow_coll = stream.arrows
line_coll = stream.lines
arrow_paths = arrow_coll.get_paths()
transform = ax1.transData.inverted()
full_transform = arrow_coll.get_transform() + transform
for idx, path in enumerate(arrow_paths):
vertices = full_transform.transform(arrow_paths[idx].vertices)
pos = np.mean(vertices, axis=0)
ax.scatter(pos[0], pos[1], marker='.')
# Display the plots
plt.tight_layout()
plt.show()

Пожалуйста, помогите, так как я немного запутался и не совсем понимаю, что возвращает вызов ax.streamplot(). В идеале я хотел бы изменить масштаб стрелок аналогично ширине линии, но решение, каким-то образом заставляющее их исчезнуть там, где поле потока равно нулю, также подойдет.
Подробнее здесь: https://stackoverflow.com/questions/792 ... matplotlib