1

I have created a plot that contains two plots within the same axis similar to this: https://matplotlib.org/1.5.1/examples/pylab_examples/ganged_plots.html

fig = plt.figure()
ax1 = fig.add_axes([0.1, 0.5, 0.8, 0.4], xticklabels=[], ylim=(-1.2, 1.2))
ax2 = fig.add_axes([0.1, 0.1, 0.8, 0.4], ylim=(-1.2, 1.2))

x = np.linspace(0, 10)
ax1.plot(np.sin(x))
ax2.plot(np.cos(x))

Is there a way to change the size of the subplots when they are on the same axis? For example, right now the subplots are both equal in size, is there I can reduce the top plot to be only a quarter of the size?

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
Selena Chavez
  • 139
  • 2
  • 10

1 Answers1

0

Positioning by hand is fine, but the more modern way to do this would be to use gridspecs:

import numpy as np
import matplotlib.pyplot as plt

fig, axs = plt.subplots(2, 1,
    gridspec_kw={'height_ratios':[1, 4], 'hspace':0}, sharex=True, sharey=True)

x = np.linspace(0, 10)
axs[0].plot(np.sin(x))
axs[1].plot(np.cos(x))
axs[0].set_ylim(-1.2, 1.2)
plt.show()
Jody Klymak
  • 4,979
  • 2
  • 15
  • 31