1

So I collected some data and I'd like to plot them and then save them. The problem is it won't work. When I execute the lines every command is executed by its own.

For example I'd like to make a Q-Q plot with a title and then save the plot as an image. For this example I just generated some random numbers.

import matplotlib.pyplot as plt
import scipy.stats as stats
import random

my_randoms = [random.randrange(1, 101, 1) for _ in range(100)]

stats.probplot(my_randoms, dist="norm", plot=plt)
plt.ylabel("Normal Q-Q plot")
plt.rcParams['figure.figsize'] = [12, 8]
plt.show()
plt.savefig("example")

The Problem is it doesn't work. When I execute the code I can see the plot but with out the title. When I execute the nex line I just see the blank plot but this time with the title and when I execute the plt.show() nothing happens.

So my question is how can I fix this. I'd like to give all my plots in my script titles and save them seperatly.

Best Regards!

Florian
  • 35
  • 3
  • Possible duplicate of https://stackoverflow.com/questions/21875356/saving-a-figure-after-invoking-pyplot-show-results-in-an-empty-file – maow Oct 31 '19 at 10:00
  • Just run the whole script or select all the `plt.` commands and run them at once – CAPSLOCK Oct 31 '19 at 10:11
  • 1
    @Gio Thank you you're right, the problem only occures when I run the lines by itself when I rund the whole script it works. Thank you! – Florian Oct 31 '19 at 10:15

0 Answers0