Issue
General Issue: My visualisation is cut on the edges and I found a way to correct it manually. But is there a command that could do it itself ?
I'm using Pyzo to code Python (Python 3.9.5
) with Matplotlib.pyplot
(version 3.4.2)
When I want to see a graph that I plotted (with
plot.show()
) command I get the plot in a separate window but it appeared cut (especially the edges : titles) as shown in the image below :Then, I tried to put it in full-window. It is slightly better but still cut (especially the top) :
So I started looking into the parameters which were accessible in the Subplot Configuration Tool
, and by changing the top
value, I was able to make my plot completely viewable:
Thus, I was wondering if there was a way to change the value directly in the code instead of having to deal with it manually each time.
Note : In the past, I had to use figsize=(x_width,y_width)
as a parameter in plt.subplots()
but it doesn't change anything here (at most, I can have the first picture above)
Recap :
- Is there a way to make sure, nothing will be cut in the visualisation of the plot (Title of the plot + Titles of the axis) with a command ?
Solution
- you can do this manually with
plt.subplots_adjust()
(https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.subplots_adjust.html) - you can do this automatically with
plt.figure(constrained_layout=True)
(https://matplotlib.org/stable/tutorials/intermediate/constrainedlayout_guide.html) - you can do this automatically with
plt.tight_layout()
instead of using constrained_layout. However, in general constrained layout is more flexible. https://matplotlib.org/stable/tutorials/intermediate/tight_layout_guide.html
Answered By - Jody Klymak
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.