Matplotlib - Vertical Height Of A Shared X-axis Figure
I would like to made the bottom of the two charts have a much smaller height. I tried set_yscale(1,.5) but it was unsucessful, looking for how to do this. Couldn't find anything in
Solution 1:
You can achieve that e.g. by using GridSpec to position the subplots in your figure. This adds a little overhead to your code, but gives you full flexibility over the plot positions and their relative widths and heights.
%matplotlib inline
import matplotlib.pyplot as plt
from matplotlib import gridspec
import numpy as np
# Simple data to display in various forms
x = np.linspace(0, 2 * np.pi, 400)
y = np.sin(x ** 2)
# create subplots' axes
fig = plt.figure()
top_pos, bot_pos = gridspec.GridSpec(2, 1, height_ratios=[4, 1])
top_ax = fig.add_subplot(top_pos)
bot_ax = fig.add_subplot(bot_pos, sharex=top_ax)
# do the plotting
top_ax.set_title('Sharing X axis')
top_ax.plot(x, y)
bot_ax.scatter(x, y)
Post a Comment for "Matplotlib - Vertical Height Of A Shared X-axis Figure"