I would like to have two subplots in Matplotlib (embedded in a GUI):
In both cases these are the same width.
GridSpec seems to not allow absolute sizing, only relative sizing. I don't want Subplot 1 to stretch its height with the window resizing.
How can I do this?
When using Matplotlib to create a figure that contains a grid of subplots, you can set the width and height of the figure by using the set_figwidth () and set_figheight () methods, respectively. Let’s examine the two examples below for more clarity.
Syntax: subplots_adjust (self, left=None, bottom=None, right=None, top=None, wspace=None, hspace=None) left : This parameter is the left side of the subplots of the figure.
This module is used to control the default spacing of the subplots and top level container for all plot elements. The subplots_adjust () method figure module of matplotlib library is used to Update the SubplotParams with kwargs. Syntax: subplots_adjust (self, left=None, bottom=None, right=None, top=None, wspace=None, hspace=None)
How to Create Different Subplot Sizes in Matplotlib? 1 Python3. import matplotlib.pyplot as plt. from matplotlib import gridspec. import numpy as np. fig = plt.figure () fig.set_figheight (8) fig. 2 Python3. 3 Python3.
If I understood your question then this code might help. It uses axes instead of subplots, which give more absolute control over the position of the plots within the figure.
import pylab as pl
# use pylab.Axes(figure, [left, bottom, width, height])
# where each value in the frame is between 0 and 1
#top
figure = pl.figure()
axes = pl.Axes(figure, [.4,.4,.25,.25])
figure.add_axes(axes)
pl.plot([1, 2, 3], [1, 2, 3])
#bottom
axes = pl.Axes(figure, [.4,.1,.25,.25])
figure.add_axes(axes)
pl.plot([1, 2, 3], [1, 2, 3])
pl.show()
If this is not what you meant, please post a snippet of code or an example to clarify.
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