I'm writing a simple Python application that uses matplotlib to display a few figures on screen. The number of figures generated is based on user input and changes throughout the application's life. The user has the ability to issue a "plot" command to generate a new figure window with the selected data series. In order to improve the user experience, I would like to provide another command that would programmatically arrange all open figure windows in some convenient arrangement (e.g. tile them across the available screen space).
I believe to have found APIs that allow me to adjust the size of the figure window (in pixels), but haven't had any success in finding a way to set their absolute position on screen. Is there a way to do this without delving into the details of whatever backend is in use? I would like to do this in a backend-agnostic way so I can avoid relying upon implementation details that might change in the future.
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.
Matplotlib can display plot titles centered, flush with the left side of a set of axes, and flush with the right side of a set of axes. Automatic positioning can be turned off by manually specifying the y keyword argument for the title or setting rcParams["axes. titley"] (default: None ) in the rcParams.
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.
FINALLY found the solution for QT backend:
import matplotlib.pyplot as plt fig, ax = plt.subplots() mngr = plt.get_current_fig_manager() # to put it into the upper left corner for example: mngr.window.setGeometry(50,100,640, 545)
If one doesn't know the x- and y-width one can read them out first, like so:
# get the QTCore PyRect object geom = mngr.window.geometry() x,y,dx,dy = geom.getRect()
and then set the new position with the same size:
mngr.window.setGeometry(newX, newY, dx, dy)
I was searching quite often for this and finally invested the 30 minutes to find this out. Hope that helps someone.
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