0

Does anyone know how to change the setting of plotting to the same monitor as the mouse cursor is to a specific monitor? I have multiple monitors and one that is dedicated for graphs, but I always need to move my mouse there quickly to make sure that the plots appear there. How can I fix this annoying issue?

Additional information that might be important: The Python library is Matplotlib. The display setting is "extended" mode.

Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
DmitryP
  • 1
  • 2
  • What library are you using matplotlib? – WMRamadan Nov 16 '22 at 09:25
  • Yes. Matplotlib. – DmitryP Nov 16 '22 at 09:36
  • You can use this to make the graphs show in the same window as your code. https://stackoverflow.com/questions/48334853/using-pycharm-i-want-to-show-plot-extra-figure-windows – WMRamadan Nov 16 '22 at 09:49
  • I definitely don't want that. I have a large display dedicated to graph visual analysis. I want all the figures to appear there. I am using extended display setting. – DmitryP Nov 16 '22 at 10:16
  • This is outside the scope of matplotlib. You will need program your window manager. On linux, I have used [devilspie2](https://www.nongnu.org/devilspie2/) for exactly your use-case. – Paul Brodersen Nov 16 '22 at 10:37
  • I am using windows. This sounds a bit extreme though. In Matlab, with a little code of figure positioning (using "get" and "set" functions) I can define where I want it to appear. Is there no similar solution in Python? – DmitryP Nov 17 '22 at 15:52

1 Answers1

0

I've found some workaround for this issue. Not an optimal solution, but worked for me. I am using matplotlib backend: Qt5Agg The workaround that I found is to move the window to a specific location and then maximize it. The location to move to would be anywhere within the display that you want the figure to appear in.

fig = plt.figure()

fig.canvas.manager.window.move(0,0)

figManager = plt.get_current_fig_manager()
figManager.window.showMaximized()

plt.plot(range(10))
plt.show()

In my case, I wanted the figures to be maximized anyway, but for those who don't want that, just moving the window using this function might be enough:

fig.canvas.manager.window.move(0,0)

The coordinates (0,0) were the corner coordinates of my main display. You can manually find what are the correct ones for your setup.

You can also set both, the position and the size of the figures manually using this approach:

fig = plt.figure()

mngr = plt.get_current_fig_manager()
posX, posY, sizeX, sizeY = (0,30, 1024, 768)
mngr.window.setGeometry(posX, posY, sizeX, sizeY)

plt.plot(range(10))
plt.show()

Thank you all for your replies. If anyone finds a better solution, please post it here.

DmitryP
  • 1
  • 2