When I create a new figure using pyplot, it opens automatically on the top left of my screen. I would like it to open at another position (for example top right of my screen). What I have been doing so far is change the position afterwards using:
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)
Is there any way I could set the desired position as default to Matplotlib? I looked up in the matplotlibrc file but found nothing that could help me... any ideas?
Import matplotlib. To change the figure size, use figsize argument and set the width and the height of the plot. Next, we define the data coordinates. To plot a bar chart, use the bar() function. To display the chart, use the show() function.
To change the position of a legend in Matplotlib, you can use the plt. legend() function. The default location is “best” – which is where Matplotlib automatically finds a location for the legend based on where it avoids covering any data points.
In this method, we will be using the pad argument of the title() function to change the title location in the given plot in the python programming language. Example: In this example, We will elevateTitleTitle by using the “pad” parameter. The offset of the Title from the top of the axes, in points.
Thank you guys for your answers. I understand these defaults are not governed by Python. The solution I found is to define a function to open a new figure and move it in the right place. This way, although I have to define or import the function each time I open a ipython console, I will not have to move each figure afterwards:
# 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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With