matplotlib graph white space

Thomas Jollans tjol at tjol.eu
Wed Oct 6 12:32:43 EDT 2021


On 04/10/2021 10:39, Steve wrote:
> I am using the first bar graph listed at this site:
> https://matplotlib.org/stable/gallery/index.html
>
> The problem I have is that there is too much white space around the graph.
> My data would be better displayed if I could widen the graph into the space
> to the right and left of the chart.
>
> Steve
>
To tweak the amount of padding around the matplotlib axes, you can use 
pyplot.subplots_adjust [1] or Figure.subplots_adjust [2].

In most cases, the tight_layout function/method [3,4] will give you 
sensible settings for the various spacing parameters.

You probably also have to adjust the figure size (see David Lowry-Duda's 
reply) to get whatever effect it is that you want.

[1] 
https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.subplots_adjust.html
[2] 
https://matplotlib.org/stable/api/figure_api.html#matplotlib.figure.Figure.subplots_adjust
[3] 
https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.tight_layout.html
[4] 
https://matplotlib.org/stable/api/figure_api.html#matplotlib.figure.Figure.tight_layout



More information about the Python-list mailing list