2017-02-22 71 views
0

當我創建使用pyplot一個新的身影,在我的屏幕的左上方會自動打開。我希望它在另一個位置打開(例如我的屏幕右上角)。 我迄今已做的是改變位置後使用:如何更改matplotlib數字的默認窗口位置?

import matplotlib.pyplot as plt 
plt.figure() # opens on the top left 
(x,y,w,h) = ... # The desired position 
plt.get_current_fig_manager().window.setGeometry(x,y,w,h) 

有什麼辦法,我可以設置爲默認Matplotlib所需的位置?我擡頭看着matplotlibrc文件,但沒有發現任何可以幫助我的...任何想法?

+0

的問題是,用於移動窗口的方法是不同的不同後端。所以我不認爲有這樣做的通用方法,因此它沒有出現在'matplotlibrc'文件中。見http://stackoverflow.com/questions/7449585/how-do-you-set-the-absolute-position-of-figure-windows-with-matplotlib?rq=1 – tom

+0

謝謝,但你提到的話題是關於手動設置位置,並且我想將它設置爲默認參數一次。我必須找出這些默認設置,而在於是否能覆蓋它們... – user7605211

+0

我的觀點是,因爲它是爲所有的後端不同的做法,我不認爲有一種方法在全球範圍內覆蓋它們。但好運氣找... – tom

回答

0

謝謝你們對你的答案。我知道這些默認設置不受Python支配。 我找到的解決方案是定義一個函數來打開一個新的人物,在正確的地方移動。這樣一來,雖然我必須定義或我每次打開一個IPython的控制檯一次導入的功能,我不會有事後移動每個人物:

# in file mymodule.py 
import matplotlib.pyplot as plt 

def newfigure(num=None): 
     hfig = plt.figure(num) 
     plt.get_current_fig_manager().window.setGeometry(x,y,w,h) 
     return hfig 

# in a python script, or in the interactive console: 
import matplotlib.pyplot as plt 
import mymodule as mm 

plt.figure() # Opens where I don't want it to 
mm.newfigure() # Opens at position (x,y) and with width and height (w,h)