Home > Back-end >  PyCharm how to display plot in seperate window on same monitor
PyCharm how to display plot in seperate window on same monitor

Time:06-03

When i plot something in PyCharm using matplotlib it plots the figure in a seperate window, which is what i want, but it also opens it on the main monitor. Is there a option to open it on my second monitor?

I could not find any similar question (only questions about plotting on the same monitor without a seperate window).

Thanks in advance!

CodePudding user response:

You can specify a position in the code

import matplotlib.pyplot as plt

fig, ax = plt.subplots()
mngr = plt.get_current_fig_manager()
# to put it into the upper left corner for example:
mngr.window.setGeometry(2000,100,640, 545)
plt.show()

CodePudding user response:

I have found a solution in another post How do you set the absolute position of figure windows with matplotlib?

def move_figure(f, x, y):
    """Move figure's upper left corner to pixel (x, y)"""
    backend = matplotlib.get_backend()
    if backend == 'TkAgg':
        f.canvas.manager.window.wm_geometry(" %d %d" % (x, y))
    elif backend == 'WXAgg':
        f.canvas.manager.window.SetPosition((x, y))
    else:
        # This works for QT and GTK
        # You can also use window.setGeometry
        f.canvas.manager.window.move(x, y)

f, ax = plt.subplots()
move_figure(f, 2200, 500)
plt.show()
  • Related