This question already has answers here:
Improve subplot size/spacing with many subplots
(8 answers)
Closed 1 year ago.
I have created a figure in python which contains multiple subplots. I have also added various axis labels to some of the axes on the figures. For examples:
plt.xlabel('Phase ($^\circ$)',fontsize=10)
I notice though, that when the final figure is produced, the other subplots are allowed to overlap and obscure the words of the axis labels.
Is there a way that I can stop this happening?
just add the following:
plt.tight_layout()
I hope it helps. Link to documentation.
Related
This question already has answers here:
How do I change the figure size with subplots?
(6 answers)
Matplotlib different size subplots
(6 answers)
Closed 2 years ago.
I would like to change the size of a graph (with multiple plots) in python to make it larger. using 'plt.figure(figsize=(6,3))' for example makes a new graph of a different size but its empty with just the axes, the actual plots do not show. can someone help me understand where i am going wrong? i have attached an image of my code in this question. thank you in advance enter image description here
Always write the plt.figure(figsize=(x,y)) before the line of code that will create the plot and end it by plt.show()
This question already has answers here:
matplotlib: can I create AxesSubplot objects, then add them to a Figure instance?
(5 answers)
pyplot - copy an axes content and show it in a new figure
(2 answers)
Closed 3 years ago.
When I want to make several subplots in a figure I can do, for example, the following
figA=plt.figure('figA',figsize=(30,25))
(ax2,ax1) = figA.subplots(2,1, gridspec_kw={'height_ratios':[1,15]})
And I can then make the plot using ax2.plot(data2) and ax1.plot(data1)
Then I might want to do another separate figure:
figB=plt.figure('figB',figsize=(30,25))
(ax2B,ax1B) = figB.subplots(2,1, gridspec_kw={'height_ratios':[1,15]})
However, I need the exact same top panel as in the previous figure.
What should I do if I want ax2B to always be identical to ax2, no matter what changes I make to the subplot?
In other words, I would like to define a subplot and apply it to several figures, rather than defining it inside a specific figure.
If for example in the top panel I want a straight line f(x)=x, I will do
import numpy as np
X=np.linspace(0.,10.,10)
ax2.plot(X,X)
ax2B.plot(X,X)
but I do not want to define the exact same plot twice. I want to just define a subplot once and for all and then call it in a new figure when I need it.
This question already has answers here:
How to remove gaps between subplots in matplotlib
(6 answers)
Closed 5 years ago.
I am attempting to plot a graph similar to the one attached below. The y-axis should be aligned and the x-axis scale and name should be same. Also, I want the dotted line as shown in the figure.
I tried combining two different graphs but that is certainly not a good way to solve this.
Sorry for the poor quality picture but the important points are mentioned.
Look into the matplotlib docs. I think you might be looking to use plt.subplots with the sharex argument.
This question already has answers here:
matplotlib.pyplot, preserve aspect ratio of the plot
(4 answers)
Closed 5 years ago.
As one can see from the above picture, 1 unit on x-asis of the graph is different from that on y-axis (in terms of length). (So you see rectangle instead of square.)
I would like to ask how can I make it the same? Thanks in advance.
You can force matplotlib to use the same scaling for both axes by adding the following to your plot:
plt.axis('equal')
More information can be found here: axis_equal_demo.py
This question already has answers here:
Matplotlib: -- how to show all digits on ticks? [duplicate]
(2 answers)
Closed 6 years ago.
On the x-axis, my units are in ns as this is what the physics dictates. However, I don't want the exponential text highlighted to be seen.
Is there anyway this can be removed while keeping the x-axis units the same?
One further question is with regards to sharing the x-axis between the two plots. I want the residual plot on the bottom to be connected to the top while resizing the y-axis.
Previously I set the hspace of the subplots to be 0 but this makes the y-axis values overlap. Are there any solutions to this?
I'd like to point out also that I'm using QuTiP if anyone has expertise in this then that'd be greatly appreciated. I'm sure it should be easy enough to convert the code into a QuTiP style either way.
Any help is appreciated!
Multiply your x data by 1e9, so that you actually plot nanoseconds.