Last answered:

16 Nov 2022

Posted on:

01 Nov 2022

0

Resolved: Saving the graph

When I am using
plt.savefig("Used-Cars.png")
Opening the resulting file returns an empty graph

4 answers ( 1 marked as helpful)
Instructor
Posted on:

02 Nov 2022

5

Hi Eslam,
thanks for reaching out! There is a small error in the video lesson, you need to write plt.savefig() before plt.show() like so:

plt.savefig("Used-Cars.png")
plt.show()

And you should have the picture saved correctly.
Let me know if that solve the issue.

Best,
365 Eli

Posted on:

02 Nov 2022

0

Yes, it works now!
Thanks

Posted on:

15 Nov 2022

0

The saved file is truncated from bottom side and the X-axis does not come complete. See below the visualization. What is the remedy?
image.png

Instructor
Posted on:

16 Nov 2022

4

Hi Dhaivat,
thanks for reaching out! You can try a couple of options to save the figure in its full size.
1. Add the bbox_inches argument when saving your picture, like so:

plt.savefig(filename, bbox_inches = 'tight')

2. Before creating your plot, run the following code:

plt.tight_layout()

3. If the two above don't work you can try and save your figure as a pdf, like so:

plt.savefig('X:/' + newName + '.pdf')

Let me know if these work for you.

Best,
365 Eli

Submit an answer