【问题标题】:Interactively Display graphs in matplotlib in python在 python 中的 matplotlib 中以交互方式显示图形
【发布时间】:2012-06-16 19:11:30
【问题描述】:

为了我的一生,我无法让matplotlibipython 中不活动地显示图表。

我尝试了两种方法 - 每次都得到相同的结果:

In [10]: plot([1,2,3])
Out[10]: [<matplotlib.lines.Line2D at 0x104e9ca50>]

到目前为止,我尝试过以下两种方法: 以the documentation 为指导,我尝试了两种不同的方法:

第一:

ipython --pylab

plot([1,2,3])
xlabel('hi mom')

In [3]: plot([1,2,3])
Out[3]: [<matplotlib.lines.Line2D at 0x107e369d0>]

第二:

ipython
import numpy
import pylab

In [5]: pylab.plot([1,2,3])
Out[5]: [<matplotlib.lines.Line2D at 0x104ca7b90>]

如何让绘图显示?

【问题讨论】:

  • 不清楚你在文本中不活跃和在标题中反复出现的意思。
  • 调用pylab.show(),或者如果您希望它们自动弹出,请在创建图形之前调用pylab.ion()
  • @PhilCooper 更新了标题。我的拼写不好。
  • @JoeKington 这两个都试过了。什么都没有“弹出”。 In [6]: pylab.ion() In [7]: pylab.plot([1,2,3]) Out[7]: [&lt;matplotlib.lines.Line2D at 0x101d59b90&gt;] In [8]: pylab.show()
  • @mikebmassey - 嗯...您是否正在运行远程会话?如果没有,请尝试@BrenBarn 的建议。如果您正在远程运行(例如通过ssh),请确保您已启用 X-forwarding。

标签: python numpy ipython matplotlib


【解决方案1】:

您可能有一个非 GUI 后端集。试试pylab.get_backend() 看看你设置了什么后端。查看文档herehere 了解如何设置您的后端。

【讨论】:

  • 刚刚检查:'MacOSX'。我看到如何通过文档更改它,但是关于使用哪一个有什么建议吗?现在,我在搞乱matplotlib,并希望在我绘制新内容时刷新我的屏幕上的图表。
  • MacOSX 应该是根据文档的 GUI 后端,所以我不知道为什么它不工作。假设您确定已将其设置为交互模式(如上面 cmets 中所建议的那样),您可以尝试文档页面上列出的任何其他交互式后端(例如,TkAgg)。您可能还想在 matplotlib 邮件列表上提问。
  • 谢谢。会打的。
猜你喜欢
  • 1970-01-01
  • 2017-09-03
  • 1970-01-01
  • 2019-10-12
  • 1970-01-01
  • 1970-01-01
  • 2012-07-30
  • 2013-04-17
  • 1970-01-01
相关资源
最近更新 更多