将序列动态添加到matplotlib

2024-05-29 03:55:30 发布

您现在位置:Python中文网/ 问答频道 /正文

我在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()

例如两个侧面像

^{pr2}$

但是我该如何处理n数量的配置文件呢?在


Tags: 代码应用程序数量matplotlib配置文件fig绘制动态
1条回答
网友
1楼 · 发布于 2024-05-29 03:55:30

您可以将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()

相关问题 更多 >

    热门问题