[英]How can I save multiple figures individually from a for loop?
我有這個for循環,它將焦點機制作為一個數字射出,我希望能夠單獨保存每個數字,但不知道如何。
for strike,dip,rake in zip(out_df.strike,out_df.dip,out_df.rake):
fig, ax = mplstereonet.subplots(figsize=(8,8))
plt.rcParams["axes.labelsize"]=14
bball = beachball.beach([strike, dip, rake]
, width=433 # scale of the beachball in the (x,y) plane
, linewidth=1 # thickness of nodal planes and beachball edge lines
, facecolor='darkblue' # color of one of the axes
, zorder=1 # make sure beachball plots on top
, axes = ax)
ax.add_collection(bball)
像下面的代碼應該做你想做的事:
m = 0
for strike,dip,rake in zip(out_df.strike,out_df.dip,out_df.rake):
m += 1
fig, ax = mplstereonet.subplots(figsize=(8,8))
plt.rcParams["axes.labelsize"]=14
bball = beachball.beach([strike, dip, rake]
, width=433 # scale of the beachball in the (x,y) plane
, linewidth=1 # thickness of nodal planes and beachball edge lines
, facecolor='darkblue' # color of one of the axes
, zorder=1 # make sure beachball plots on top
, axes = ax)
ax.add_collection(bball)
plt.savefig(f"figure_{m}.png")
plt.close()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.