python - Getting the bottom axes in a matplotlib for labelling -
i'd add labels grid of plots, @ bottom axes. don't created axes, have query them fig.get_axes() (this means example below: can not access value ax). nevertheless of these axes have been created subplots shared x-axis.
as example use simplified example:
# illustration purpose have no # knowledge how original plot created import numpy np import pylab plt fig, ax = plt.subplots(2, 3, sharex=true) x = np.arange(0, 5, 0.1) n = 0 in xrange(2): j in xrange(3): y = x ** n ax[i, j].plot(x, y) n += 1 # real work starts here axes = fig.get_axes() print axes plt.show() i'd use data retrieved in axes 3 bottom axes , label them. note: number of columns may vary , unknown.
don't permanently flatten array of axes. it's shape tell label. in fact, use ravel instead of flatten view of original ax array instead of making unncessary copy: what difference between flatten , ravel functions in numpy?
import numpy np import pylab plt fig, ax = plt.subplots(2, 3, sharex=true) x = np.arange(0, 5, 0.1) fax = ax.ravel() in xrange(6): y = x ** fax[i].plot(x, y) in range(ax.shape[1]): ax[-1, i].set_xlabel("some junk {}".format(i)) plt.show()
Comments
Post a Comment