【问题标题】:multiple figures in matplotlibmatplotlib 中的多个数字
【发布时间】:2016-02-06 01:58:46
【问题描述】:

我实际上是新来的,我刚开始为我的硕士论文项目使用 python。我尝试绘制多个数字,但我不能。我看过许多相同的问题和答案,但仍然无法得到结果。

plt.figure(1)
plt.draw()
plt.axis([14,55, 3, 5])
plt.xlabel('doy')
plt.ylabel('amplitudes of L1 & L2 signals')
red_dot, = plt.plot(X1, L1,'ro')
green_dot, = plt.plot(X1, L2, 'go')
plt.legend([red_dot, green_dot], ["L1", "L2"])



plt.figure(2)
plt.draw() 
plt.axis([14,55, 25, 60])
plt.xlabel('doy')
plt.ylabel('dampenings of L1 & L2 signals')
red_dot, = plt.plot(X1, damp_L1,'ro')
green_dot, = plt.plot(X1, damp_L2, 'go')
plt.legend([red_dot, green_dot], ["dampening of L1", "dampening of L2"])


plt.show()

这就是我写的,我唯一得到的是一个带有第一个图的图形 1 和一个空的图形 2 窗口,里面没有数据! 有人可以帮忙吗?

谢谢

【问题讨论】:

标签: python matplotlib plot


【解决方案1】:

我强烈建议尽可能使用 OO 接口(而不是 pyplot '状态机' API)。你想要的是这样的:

fig1, ax1 = plt.subplots()
fig2, ax2 = plt.subplots()

ax1.plot(x, y, 'ro')

ax2.plot(x, y, 'go')

运行这些命令一个 ipython 会话(在执行 %matplotlib 之后)将为您提供两个可交互的图形。

【讨论】:

  • 谢谢你的回答我的朋友。我照你说的做了: fig1, ax1 = plt.subplots() fig2, ax2 = plt.subplots() ax1.plot(X1, L1, 'ro', X1, L2, 'go') ax2.plot(X1, damp_L1, 'ro', X1, damp_L2, 'go') plt.show() 但我得到的只是两个带有 4 个点的数字。 1个绿色和1个红色!
  • A. Drosi,tcaswell 的回答是正确的。也许所有图都没有显示,因为您在每个图上错误地定义了plt.axis?如果您没有显示 X1、L1、... 数组的示例,那么这个答案是最有人可以帮助您的
  • 大家好。我以其他方式工作。尽管@iblasi,我并不怀疑给定的答案!无论如何,我做了一些看起来很奇怪但有效的事情。我创建了 2 个列表并将数据放入这两个列表中。然后,我只是绘制了列表并使用了 plt.figure(1) 和 plt.figure(2) 并且它起作用了。
猜你喜欢
  • 2022-01-26
  • 2017-12-26
  • 1970-01-01
  • 2018-08-10
  • 2022-01-26
  • 2015-11-23
  • 2011-03-13
  • 2023-03-27
  • 1970-01-01
相关资源
最近更新 更多