python - plot a large number of axis objects using one command through a loop -
say have bunch of ax1,ax2,ax3... , want run them through plotting function:
def plotxy(ax,x,y): x = np.array(x) y = np.array(y) ax.plot(x,y)
(obviously simplified)
how repeat command without doing:
plotxy(ax1,x,y) plotxy(ax2,x,y) ... plotxy(axn,x,y)
i'm sure there way create temp variable holds axn in loop 1 line. ideas? shorten code i've got heaps of things need plot same command differing x & y , on multiple subplots.
i guess part of large question of constructing variable names using loop?
you can try this:
import matplotlib.pyplot plt fig, axs = plt.subplots(nrows=3, ncols=2) ax in axs.flat: plotxy(ax,x,y)
if use plt.subplot
or plt.axes
can create list/array of axes hand
Comments
Post a Comment