简体   繁体   中英

How to plot and save separate plots using matplot lib and python

I am trying to plot 6 different plots on matplot lib and save them each to a folder. However, it looks like they are all plotting on top of each other, so the first saved image is correct, but the second is just the second plot on top of the first plot. I would like the second plot, and all following, to just be that plot, not on top of the previous one. This is the code I have used, thank you so much!

for x in range(len(sizeDict)):
    plt.plot(xAxis,sizeDict[x])
    plt.title('size'+str(x))
    plt.savefig("/Users/name/Desktop/Work/Size"+ str(x) + ".png")

for x in range(len(shapeDict)):
    plt.plot(xAxis,shapeDict[x])
    plt.title('shape'+str(x))
    plt.savefig("/Users/Name/Desktop/Work/Shape"+ str(x) + ".png")

You need to either create another figure or close the current one. You can use plt.figure() to create a new one or plt.close() to close the current one.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM