Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 向matplotlib动态添加系列_Python_Matplotlib - Fatal编程技术网

Python 向matplotlib动态添加系列

Python 向matplotlib动态添加系列,python,matplotlib,Python,Matplotlib,我正在matplotlib中制作一个绘制翼型剖面的应用程序,我需要在同一个子地块中绘制多个剖面。我知道如何添加固定数量的系列,但不知道如何动态添加。我的个人资料代码为: pts = d['AG17'] fig = plt.figure() ax = fig.add_subplot(111, aspect='equal') ax.plot(pts[:, 0], pts[:, 1], '-r') ax.grid() plt.show() 例如,对于两个配置文件 ax.plot(pts[:, 0]

我正在matplotlib中制作一个绘制翼型剖面的应用程序,我需要在同一个子地块中绘制多个剖面。我知道如何添加固定数量的系列,但不知道如何动态添加。我的个人资料代码为:

pts = d['AG17']

fig = plt.figure()
ax = fig.add_subplot(111, aspect='equal')
ax.plot(pts[:, 0], pts[:, 1], '-r')
ax.grid()
plt.show()
例如,对于两个配置文件

ax.plot(pts[:, 0], pts[:, 1], '-r', pts1[:, 0], pts1[:, 1], '-r')

但是,如何为
n
数量的配置文件执行此操作?

您可以将
ax.plot
调用放入for循环中:

profiles = ['AG17','AG18','AG19', ... , etc.] # I'm guessing at your profile names!
linestyles = ['r-','b--','g:', ..., etc.] # Use this if you want different colors or linestyles for each profile

fig = plt.figure()
ax = fig.add_subplot(111, aspect='equal')

for prof, ls in zip(profiles,linestyles):
    pts = d[prof]
    ax.plot(pts[:, 0], pts[:, 1], ls)

ax.grid()
plt.show()

您可以对单个子地块进行多个
plot
调用。如果要进行多个
LineCollection
调用,也可能对您有用