Reputation: 1273
If the following code is run
import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
a=[[1,2,3],[4,4,4]]
gridspec.GridSpec(2,1)
plt.subplot2grid((2,1), (0,0), colspan=2, rowspan=1)
plt.figure(figsize=(10, 5))
plt.imshow(a)
plt.savefig('fig.png',bbox_inches='tight')
I got the picture below. How to set the width/height ratio of subplot as 1:2, so it can be longer?
Upvotes: 2
Views: 1587
Reputation: 339230
By default matplotlib shows images with a 1:1 aspect ratio, i.e. each pixel is as wide as it is high. Aspect is defined as height/width. You can set aspect=2
to get an image with pixels twice as heigh as wide.
plt.imshow(a, aspect=2)
Upvotes: 3