简体   繁体   中英

Python Matplotlib : savefig graphs in for loop

I try to save scatter plots created with a for loop:

for i in df["Canal de distribution"].unique():
    fig, ax = plt.subplots(figsize=(10,7))
    ax.scatter(df[df["Canal de distribution"]==str(i)]["date"],df[df["Canal de distribution"]==str(i)]["Prix"],alpha=.7)
    fig.savefig("distribution données canal : {} .png".format(i), transparent=False, dpi=300,bbox_inches='tight', facecolor=(1,1,1,0))
    plt.show()

The graphs are created but nothing is saved. Any idea what I am missing?

EDIT: I noticed a filed saved under the name "distribution données canal " (same as in savefig) but without any extension and just one, weird weird

Change the:

fig.savefig("distribution données canal : {} .png".format(i), transparent=False, dpi=300,bbox_inches='tight', facecolor=(1,1,1,0))

To:

plt.savefig("distribution données canal : {} .png".format(i), transparent=False, dpi=300,bbox_inches='tight', facecolor=(1,1,1,0))

Using alaniwi's input I removed the colon from my savefig title and it worked

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