How do you set the absolute position of figure windows with matplotlib?
there is not that I know a backend-agnostic way to do this, but definitely it is possible to do it for some common backends, e.g., WX, tkagg etc.
import matplotlib
matplotlib.use("wx")
from pylab import *
figure(1)
plot([1,2,3,4,5])
thismanager = get_current_fig_manager()
thismanager.window.SetPosition((500, 0))
show()
per @tim at the comment section below, you might wanna switch to
thismanager.window.wm_geometry("+500+0")
instead. For TkAgg
, just change it to
thismanager.window.wm_geometry("+500+0")
So I think you can exhaust through all the backends that are capable of doing this, if imposing a certain one is not an option.
Python on windows, open plot windows next to each other
You can choose the location of your plot but it is dependant on backend. To check this,
import matplotlib
matplotlib.get_backend()
and then see this answer for various ways to adjust.
For example, this works for me on linux with Qt4Agg
,
import matplotlib.pyplot as plt
#Choose the correct dimensions for your first screen
FMwidth = 1280
FMheight = 1024
#Choose the correct dimensions for your second screen
SMwidth = 1280
SMheight = 1024
fm = plt.get_current_fig_manager()
#Works with QT on linux
fm.window.setGeometry(FMwidth,0,SMwidth,SMheight)
This may be better for windows
fm.window.wm_geometry("+500+0")
You may also be able to get the screen size(s) from,
from win32api import GetSystemMetrics
width = GetSystemMetrics(0)
weight = GetSystemMetrics(1)
You can easily create a counter which increments whenever you create a plot and adjusts this specified position so the next plot is next to the previous one each time. However, the size and layout are much easier if you use subplots, for example to set up your 2 by 3 grid,
#Setup 2 by 3 grid of subplots
fig, axs = plt.subplots(2,3,figsize=(width,height))
axs[0,0].plot(x, np.sinc(x))
axs[1,0].hist(y)
etc
You can then use your counter to specify which plot you are currently using and increment this whenever you plot.
How do you set the absolute position of figure windows with matplotlib?
there is not that I know a backend-agnostic way to do this, but definitely it is possible to do it for some common backends, e.g., WX, tkagg etc.
import matplotlib
matplotlib.use("wx")
from pylab import *
figure(1)
plot([1,2,3,4,5])
thismanager = get_current_fig_manager()
thismanager.window.SetPosition((500, 0))
show()
per @tim at the comment section below, you might wanna switch to
thismanager.window.wm_geometry("+500+0")
instead. For TkAgg
, just change it to
thismanager.window.wm_geometry("+500+0")
So I think you can exhaust through all the backends that are capable of doing this, if imposing a certain one is not an option.
Related Topics
How to Use Groupby to Concatenate Strings in Python Pandas
Comprehension for Flattening a Sequence of Sequences
How to Include Related Model Fields Using Django Rest Framework
Removing Duplicates from Dictionary
How to Convert a String to Utf-8 in Python
Matplotlib Savefig() Plots Different from Show()
Matplotlib: How to Plot Images Instead of Points
Typeerror: 'Dict' Object Is Not Callable
How to Use SQL Parameters with Python
Why Does My Pandas Dataframe Not Display New Order Using 'Sort_Values'
How Does a Python for Loop with Iterable Work
How to Use a Multiprocessing.Manager()
How to Automatically Fix an Invalid JSON String
Getting Individual Colors from a Color Map in Matplotlib
Downloading with Chrome Headless and Selenium
Getting Rid of Console Output When Freezing Python Programs Using Pyinstaller