Update/Refresh 第二台显示器上的 matplotlib 图

Update/Refresh matplotlib plots on second monitor

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

有什么方法可以将我的 matplotlib 图放在第二台显示器上并从主显示器刷新它们吗?

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

这里有一些额外的信息:

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

这与 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()

我知道这是一个老问题,但我遇到了类似的问题并找到了这个问题。我设法使用 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?