Home  >  Q&A  >  body text

python - How to change the path of matplotlib.pyplot.save

By default, it is always saved in the same folder as the py file. How can I change the path and save the generated image on the path I want?

为情所困为情所困2710 days ago1417

reply all(1)I'll reply

  • PHPz

    PHPz2017-05-18 10:47:14

    In matplotlib, pyplot does not have a save function. If you want to save a picture, you can refer to the following simple example:

    >>> from matplotlib import pyplot as plt
    >>> x=[2,5]
    >>> y=[4,9]
    >>> plt.plot(x,y)
    >>> plt.savefig('D:\img.jpg')

    Of course you can also save it in PDF format:

    >>> plt.savefig('D:\img.pdf')

    matplotlib will handle this part of the work automatically.

    reply
    0
  • Cancelreply