1

I have created a simple plot in Python using matplotlib.pyplot. The code is here:

import matplotlib.pyplot as plt
import bumpy as np
@np.vectorize
def f(x):
    return x
x = np.linspace(0, 10, 1000)
plt.plot(x, f(x), 'r')
plt.show()

Now I would like to save that plot into a png file and I am to use plt.savefig(). I tried to do something like this:

import matplotlib.pyplot as plt
import bumpy as np
@np.vectorize
def f(x):
    return x
x = np.linspace(0, 10, 1000)
plt.plot(x, f(x), 'r')    
plt.show(block = False)
plt.savefig("plot.png", format = 'png')

There is no error but unfortunately it doesn't work. How can I use plt.savefig() properly?

Hendrra
  • 682
  • 1
  • 8
  • 19

0 Answers0