1

I am trying to run a plotting on different desktop. But I could find any solution for moving the figure on another desktop.
for example if the following is my code:

import matplotlib.pyplot as plt
import numpy as np
plt.ion()
fig = plt.figure()
fig.set_size_inches(50,70)
ax = fig.add_subplot(111)
line1, = ax.plot(np.arange(0,10),color='blue', label='original values',marker=".")
plt.show()

Then how I can make this figure appear on the second desktop rather than on first desktop.
See the following is the figure I am getting :
getting image like this

and I am expecting that the image should appear on the second desktop in full screen if possible. Like the following:
expected image

Please let me know if you have any idea what I can try and do to achieve what I am expecting.

I tried the command matplotlib.get_backend() I saw this: TkAgg

Community
  • 1
  • 1
Jaffer Wilson
  • 7,029
  • 10
  • 62
  • 139
  • On linux, you would achieve this via a window matching utility like devilspie2. Pretty sure that matplotlib just uses whatever it is given by the OS as your primary display. – Paul Brodersen Apr 04 '19 at 10:20
  • Then is there nothing we could do? – Jaffer Wilson Apr 04 '19 at 10:41
  • 2
    This answer works for me on QT4Agg backend - https://stackoverflow.com/a/35797374/5851928 – DavidG Apr 04 '19 at 10:45
  • That is an ingenious hack. Out of the box, it will only work if the secondary display is "right" of the primary one. Obviously the logic can be adapted to any other position though. – Paul Brodersen Apr 04 '19 at 10:51
  • @DavidG I tried but there are some issues on my system as I am trying to run the solution. I have install PySide2 and PyQt5 using pip but still there are errors. Is there any other methodology for that? – Jaffer Wilson Apr 04 '19 at 10:58
  • I am getting this error with @DavidG solution: ` "Matplotlib qt-based backends require an external PyQt4, PyQt5,\n"` I tried installations still not working. Anybody? – Jaffer Wilson Apr 04 '19 at 11:04
  • When I tried the command `matplotlib.get_backend()` I saw this: `TkAgg`. Now is there any solution for that? – Jaffer Wilson Apr 04 '19 at 12:08

1 Answers1

0

If you don't want to install Qt, just use Tkinter and then move the window to your 2nd desktop.

import matplotlib.pyplot as plt
import matplotlib
matplotlib.use("TkAgg")
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
import numpy as np
import tkinter as tk

root = tk.Tk()
root.geometry("500x500")
fig = plt.figure()
fig.set_size_inches(50,70)
ax = fig.add_subplot(111)
line1, = ax.plot(np.arange(0,10),color='blue', label='original values',marker=".")
canvas = FigureCanvasTkAgg(fig,root)
canvas.get_tk_widget().pack(fill=tk.BOTH,expand=True)

#if you want to automatically move the screen to 2nd monitor
#def move_to_right_screen():
#    root.geometry(f"{root.winfo_screenwidth()+1}x500")
#    root.state('zoomed')
#move_to_right_screen()

root.mainloop()
Henry Yik
  • 22,275
  • 4
  • 18
  • 40