簡體   English   中英

使用帶有MacOSX后端的python matplotlib設置圖形的絕對位置

[英]Setting the absolute position of a figure using python matplotlib with the MacOSX backend

是否可以使用帶有MacOSX后端的matplotlib在屏幕上設置圖形的絕對位置?

這個答案

如何使用matplotlib設置圖形窗口的絕對位置?

表示可以在其他后端執行此操作,但未提及如何在MacOSX后端執行此操作。

使用MacOSX后端 ,無法設置matplotlib窗口的窗口位置。 但是一般來講, 在MacOSX下,您可以使用其他允許這樣做的matplotlib后端。 應該自動安裝TkAgg后端(通過Python標准庫中的Tkinter綁定使用Tcl/Tk )。

在您的python腳本中,首先,請切換到此后端,然后創建您的繪圖並顯示它,現在您可以使用

get_current_fig_manager().window.wm_geometry("+<x-pos>+<y-pos>")

這是一個工作示例:

import matplotlib
matplotlib.use("TkAgg") # set the backend
import matplotlib.pyplot as plt

plt.figure()
plt.plot([0,1,2,0,1,2]) # draw something
plt.show(block=False)

plt.get_current_fig_manager().window.wm_geometry("+600+400") # move the window

如果您安裝帶有PyQt綁定的IMHO更好的Qt4 GUI框架,則使用

get_current_fig_manager().window.setGeometry(<x-pos>,<x-pos>,<width>,<height>)

再次是完整的示例:

import matplotlib
matplotlib.use("Qt4Agg") # set the backend
import matplotlib.pyplot as plt

plt.figure()
plt.plot([0,1,2,0,1,2]) # draw something
plt.show(block=False)

plt.get_current_fig_manager().window.setGeometry(600,400,1000,800)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM