swcarpentry / python-novice-gapminder

Plotting and Programming in Python
http://swcarpentry.github.io/python-novice-gapminder/
Other
162 stars 428 forks source link

savefig truncates figure elements #638

Open ensatina opened 1 year ago

ensatina commented 1 year ago

In the examples for using the savefig() function on page 9 [Please](http://swcarpentry.github.io/python-novice-gapminder/09-plotting.html), the exported figures truncate axis labels.

Is there an easy (appropriate level) modification that could be added so the full figures export? I'm new to Python and this immediately sent me away from the lesson to troubleshoot, so I think it would be good if the code in the lesson exported full figures.

I ended up adding the argument

bbox_inches = "tight"

but I don't know what it means or if there is a better way to do this.

martinosorb commented 1 year ago

Hi @ensatina, indeed what you did there is correct. Matplotlib unfortunately has default options that are not always great.

Are you suggesting we add that argument to the lesson? Personally I would rather keep it simple to avoid lengthy explanations in the course of the workshops. As your own case suggests, it is possible to debug that problem with a bit of googling in case it arises for a learner after the workshop. What do you think?

vahtras commented 1 year ago

A common way is to include the function call fig.tight_layout(), which probably results in something similar. One could put this before a fig.savefig in the example and a short one-sentenace comment will suffice.

On Thu, May 18, 2023 at 3:08 PM Martino Sorbaro @.***> wrote:

Hi @ensatina https://github.com/ensatina, indeed what you did there is correct. Matplotlib unfortunately has default options that are not always great.

Are you suggesting we add that argument to the lesson? Personally I would rather keep it simple to avoid lengthy explanations in the course of the workshops. As your own case suggests, it is possible to debug that problem with a bit of googling in case it arises for a learner after the workshop. What do you think?

— Reply to this email directly, view it on GitHub https://github.com/swcarpentry/python-novice-gapminder/issues/638#issuecomment-1553032289, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABLLJBLSPNW42MPXWNO4O33XGYNOHANCNFSM6AAAAAAX4KWM3Y . You are receiving this because you are subscribed to this thread.Message ID: @.***>