Time Series Plotted With Imshow
I tried to make the title as clear as possible although I am not sure it is completely limpid. I have three series of data (number of events along time). I would like to do a subpl
Solution 1:
Using fig.subplots_adjust(hspace=0)
sets the vertical (height) space between subplots to zero but doesn't adjust the vertical space within each subplot. By default, plt.imshow
has a default aspect ratio (rc image.aspect
) usually set such that pixels are squares so that you can accurately recreate images. To change this use aspect='auto'
and adjust the ylim
of your axes accordingly.
For example:
# you don't need all the `expand_dims` and `vstack`ing. Use `reshape`
x0 = np.linspace(5, 0, 25).reshape(1, -1)
x1 = x0**6
x2 = x0**2
fig, axes = plt.subplots(3, 1, sharex=True)
fig.subplots_adjust(hspace=0)
for ax, x inzip(axes, (x0, x1, x2)):
ax.imshow(x, cmap='autumn_r', aspect='auto')
ax.set_ylim(-0.5, 0.5) # alternatively pass extent=[0, 1, 0, 24] to imshow
ax.set_xticks([]) # remove all xticks
ax.set_yticks([]) # remove all yticks
plt.show()
yields
To add a colorbar, I recommend looking at this answer which uses fig.add_axes()
or looking at the documentation for AxesDivider
(which I personally like better).
Post a Comment for "Time Series Plotted With Imshow"