1

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

8
  • 1
    Very odd - it ought to work. Can you just check if you are in the correct directory? Insert print(os.getcwd()). Commented Jul 5, 2020 at 21:09
  • Yes it prints the same directory Commented Jul 5, 2020 at 21:11
  • There are settings in our pc that controls whether we see the extension or not. Commented Jul 5, 2020 at 21:14
  • 2
    Still very strange. Can you try without the colon? What operating system are you using? Commented Jul 5, 2020 at 21:16
  • 2
    I suggested it because it was truncated at the colon, based on your report, and I'm aware that Windows uses colon as a separator for the drive letter, so was prepared to believe that it might do something odd under Windows (though I don't use Windows myself). Hence my question about OS. Commented Jul 5, 2020 at 21:21

2 Answers 2

0

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))
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your reply Ann, unfortunately the result is the same: graph displayed but not saved
0

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

2 Comments

See this answer. It looks like it is just rooted that colon (':') is a non-allowed character for files on some systems. Would be nice if it gave a warning though!
Good call Tom, lesson learned I will not use it in my titles for some time!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.