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.
Related
This question already has answers here:
How to add hovering annotations to a plot
(12 answers)
Closed 3 years ago.
How can I plot a figure in Python like MATLAB with the following features?:
1) I can zoom in and zoom out.
2) I can modify the range for x and y on the figure
3) I can click on the figure to see actual numbers related to each data point
Another question, how can we specify with wath resolution the matplotlib saves the figure?
To the best of my knowledge, MATPLOTLIB does not have that. Anything else?
I would recommend looking at plotly.
Plotly allows you to make graphs that can be
1) zoomed in on
2) change the x and y-axis numbers by dragging on the axes (but cant switch from say, log scale to linear scale as easily -- something like this would require an interaction feature)
3) Plotly allows you to display info on cursor-hover
For an example of a plotly plot in use, see this washington post page.
This question already has answers here:
How to adjust padding with cutoff or overlapping labels
(8 answers)
Closed 4 years ago.
So I'm using yellowbrick in Python, which is basically matplotlib and scikit-learn combined, to visualize some data.
My chart looks like this:
The labels get cut off. What I want to do is to adjust the figure so the labels on the right don't get cut off. I tried
plt.rcParams['figure.figsize'] = (10, 5)
plt.rcParams['font.size'] = 12
but when I rendered the figure, it's still cut off. Even when I save it as a png file it's still cut off. What am I missing here?
tight_layout method should solve your problem.
Generally you can use it with:
fig.tight_layout() # if fig is your figure handle
or
plt.tight_layout() # if stated within the context of your figure
This line of code should be added after the last plotting statement just before rendering the figure.
If this does not work, please post a fully working minimal code example, as described in mcve. Afterwards I'll be able to post a fully working solution for most, if not all, cases.
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.
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.