【发布时间】:2019-08-28 19:26:26
【问题描述】:
我有以下 x 和 y numpy 数组。我希望将它们绘制在一个图中,例如 XY 网格上的点或点。在 MATLAB 中,在每次调用绘图函数之后,我都会坚持下去,然后再向我展示整个绘图。
PYthon 的替代方案是什么?以下代码绘制了每个点,并且必须关闭图形,以便它可以在另一个图形上绘制下一个点。但是,我希望将所有点都放在同一张图上。
寻找有关如何使用 Python 实现这一目标的建议
import numpy as np
import matplotlib.pyplot as plt
a = 12; # Max length of spray wall; a is x direction in FEET
b = 12; # Max width of spray wall; b is y direction in FEET
w = 1; # Width of spray pattern in INCHES
l = 12 ; # Length of spray pattern in INCHES
l = l/12; # IN FEET
ex = np.linspace(w/2, a - w/2, a*50); # THe resolution here is user preference or the speed
ey = np.linspace (l/2, b - l/2, int(2*b/l) -1); # The resolution here is based on 50 % overlap
for y in ey:
for x in ex:
plt.plot(x, y, '*')
plt.show()
我不能使用 scatter,因为 ex 和 ey 的长度必须相同
【问题讨论】:
-
将
plt.show()放在代码中要显示绘图的位置的所有循环之外。
标签: python matplotlib