1

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 the documentation.

import matplotlib.pyplot as plt
import numpy as np

# Simple data to display in various forms
x = np.linspace(0, 2 * np.pi, 400)
y = np.sin(x ** 2)



# Two subplots, the axes array is 1-d
f, axarr = plt.subplots(2, sharex=True)
axarr[0].plot(x, y)
axarr[0].set_title('Sharing X axis')
axarr[1].scatter(x, y)
axarr[1].set_yscale(1,.5)

plt.show()
user2242044
  • 8,803
  • 25
  • 97
  • 164
  • You mean the whitespace under each plot? – elyase Jan 16 '15 at 17:16
  • @elyase no, I mean the actual height of the graph. Right now the height of the top and bottom graph are equal. I want the height of the bottom graph to be half the height of the top graph. – user2242044 Jan 16 '15 at 17:24

1 Answers1

2

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)

result

cel
  • 30,017
  • 18
  • 97
  • 117