【问题标题】:Update/Refresh matplotlib plots on second monitor在第二台显示器上更新/刷新 matplotlib 图
【发布时间】:2015-01-09 13:42:31
【问题描述】:

目前我正在使用 Spyder 并使用 matplotlib 进行绘图。我有两台显示器,一台用于开发,另一台用于(数据)浏览和其他东西。由于我正在做一些计算并且我的代码经常更改,因此我经常(重新)执行代码并查看图表以检查结果是否有效。

有什么方法可以将我的 matplotlib 图放在第二个监视器上并从主监视器刷新它们?

我已经搜索了解决方案,但找不到任何东西。这对我真的很有帮助!

以下是一些附加信息:

操作系统:Ubuntu 14.04(64 位) Spyder 版本:2.3.2 Matplotlib-版本:1.3.1.-1.4.2.

【问题讨论】:

  • (Spyder dev here) 让我看看我是否正确理解了你的问题:你重新运行你的脚本,生成 matplotlib 图,而你的图没有更新第二台显示器?另一个问题:您的操作系统和 Spyder、matplotlib 和 Python 的版本是什么?谢谢:-)
  • 是的,如果我重新运行脚本(在我的第二台显示器上最大化第一次运行的图),则会打开一个新图并将其放置在我的第一台显示器上。我正在使用 Spyder 2.3.2 和 matplotlib 1.3.1 在 Ubuntu 14.04(64 位)下工作。感谢您的帮助!
  • 这似乎是 matplotlib 的问题,而不是 Spyder 的问题。也许更新到 matplotlib 1.4.2 会对您有所帮助。很抱歉没有提供更多帮助。
  • 我现在已经更新到 matplotlib 1.4.2。仍然有同样的问题.. 还是谢谢!
  • 尝试在 matplotlib issue tracker 中发布问题。也许 mpl 家伙可以帮助你:-)

标签: python matplotlib scientific-computing spyder


【解决方案1】:

这与 matplotlib 无关,与 Spyder 无关。明确地放置一个图形的位置似乎是其中一种真正有解决方法的事情......请参阅问题here的答案。这是一个老问题,但我不确定从那以后是否发生了变化(任何 matplotlib 开发人员,请随时纠正我!)。

第二台显示器应该没有任何区别,听起来问题只是这个数字正在被一个新的取代。

幸运的是,您可以非常轻松地更新已移动到所需位置的图形,具体方法是使用对象接口,并在不创建新图形的情况下更新 Axes 对象。下面是一个例子:

import matplotlib.pyplot as plt
import numpy as np

# Create the figure and axes, keeping the object references
fig = plt.figure()
ax = fig.add_subplot(111)

p, = ax.plot(np.linspace(0,1))

# First display
plt.show()

 # Some time to let you look at the result and move/resize the figure
plt.pause(3)

# Replace the contents of the Axes without making a new window
ax.cla()
p, = ax.plot(2*np.linspace(0,1)**2)

# Since the figure is shown already, use draw() to update the display
plt.draw()
plt.pause(3)

# Or you can get really fancy and simply replace the data in the plot
p.set_data(np.linspace(-1,1), 10*np.linspace(-1,1)**3)
ax.set_xlim(-1,1)
ax.set_ylim(-1,1)

plt.draw()

【讨论】:

  • 感谢您的回答!您的代码运行良好,但实际上不是我正在寻找的。也许是因为我的公式有点不清楚。对我来说,如果我用绘图命令重新运行我的代码,绘图窗口保持在第二个监视器上并保持它的位置很重要。
  • 在更新到 matplotlib 1.4.2 之后,所有新图都以某种方式“记住”了最后一个图的监视器。因此,出于我的目的,我只需要确保位置与我通过使用此问题 (stackoverflow.com/questions/12439588/…) 中的代码最大化窗口来解决的位置相同,无论如何,感谢您的回答!下次我会尝试更清楚地表达自己;)
【解决方案2】:

我知道这是一个老问题,但我遇到了类似的问题并找到了这个问题。我设法使用 QT4Agg 后端将我的绘图移动到第二个显示器。

import matplotlib.pyplot as plt
plt.switch_backend('QT4Agg')

# a little hack to get screen size; from here [1]
mgr = plt.get_current_fig_manager()
mgr.full_screen_toggle()
py = mgr.canvas.height()
px = mgr.canvas.width()
mgr.window.close()
# hack end

x = [i for i in range(0,10)]
plt.figure()
plt.plot(x)

figManager = plt.get_current_fig_manager()
# if px=0, plot will display on 1st screen
figManager.window.move(px, 0)
figManager.window.showMaximized()
figManager.window.setFocus()

plt.show()

[1] 来自@divenex 的回答:How do you set the absolute position of figure windows with matplotlib?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-02-26
    • 1970-01-01
    • 2012-03-03
    相关资源
    最近更新 更多