简体   繁体   English

在另一个桌面Matplotlib Python上设置图

[英]Setting the plot on another desktop Matplotlib Python

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 : 看到以下是我得到的数字:
得到这样的形象

and I am expecting that the image should appear on the second desktop in full screen if possible. 并且我希望该图像应尽可能全屏显示在第二个桌面上。 Like the following: 如下所示:
预期的图像

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 我尝试了命令matplotlib.get_backend()我看到了: TkAgg

If you don't want to install Qt, just use Tkinter and then move the window to your 2nd desktop. 如果您不想安装Qt,请使用Tkinter,然后将窗口移至第二个桌面。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM