python - How to set axes limits in each subplot -
i created subplot figure code:
f, axs =plt.subplots(2,3)
now on loop make plot on each subplot doing:
for in range(5): plt.gcf().get_axes()[i].plot(x,u)
is there similar code set axis limits of subplot i'm accessing ?
yes can use .set_xlim , .set_ylim on axessubplot object get_axes()[i].
example code in style gave:
import numpy np matplotlib import pyplot plt f, axs =plt.subplots(2,3) x = np.linspace(0,10) u = np.sin(x) in range(6): plt.gcf().get_axes()[i].plot(x,u) plt.gcf().get_axes()[i].set_xlim(0,5) plt.gcf().get_axes()[i].set_ylim(-2,1)
or more pythonically:
import numpy np matplotlib import pyplot plt f, axs =plt.subplots(2,3) x = np.linspace(0,10) u = np.sin(x) sub_plot_axis in plt.gcf().get_axes(): sub_plot_axis.plot(x,u) sub_plot_axis.set_xlim(0,5) sub_plot_axis.set_ylim(-2,1)
Comments
Post a Comment