当我使用 pyplot 创建一个新图形时,它会自动在我的屏幕左上角打开。我希望它在另一个位置打开(例如我屏幕的右上角)。到目前为止我一直在做的是使用以下方法更改位置:
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)
Run Code Online (Sandbox Code Playgroud)
有什么办法可以将所需的位置设置为 Matplotlib 的默认位置吗?我在 matplotlibrc 文件中查找,但没有发现任何可以帮助我的东西......有什么想法吗?
谢谢你们的回答。我知道这些默认值不受 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)
Run Code Online (Sandbox Code Playgroud)