I am working on converting some MATLAB plotting code to Python / matplotlib. The original MATLAB code contains this:
F = figure; % ... create subplots and draw on one of them ... F.Position = [400 80 650 10];
I am trying to determine the matplotlib equivalent of the assignment to F.Position
.
MATLAB docs describe this property as conveying the location and size of the drawable area, but matplotlib.figure.Figure
does not appear to have a corresponding property.
matplotlib.axes.Axes
does seem to have such position — at least two positions, in fact — but I’m uncertain whether this is the corresponding property, in part because MATLAB Axes also have their own positions. If this is the right place to look then which Axes
should be affected? The current ones? Those of all subplots? Those of the not-yet-drawn subplots? Something else? And which of the positions of those Axes
should be affected? Or am I barking up the wrong tree?
Update:
I am aware of the matplotlib figure size property. I take the figure offsets expressed in the MATLAB version to be important, so I don’t think that adjusting the figure size alone will be adequate.
Advertisement
Answer
If you don’t care about exactly where on your screen it shows up, then it might be good enough to set the size of the figure:
fig = plt.figure(figsize=(width,height))
The default units are inches, but that can be changed: https://matplotlib.org/stable/gallery/subplots_axes_and_figures/figure_size_units.html
If you do care about the position, it looks like it’s described in more detail here: How do you set the absolute position of figure windows with matplotlib?