I'm having a hard time to make some of my figures in my paper aligned appropriately.
Here is the problem. I have two figures that I want to use the same x-axis. I plot two figures separately and include them as two subfigures in Latex. The problem with this: the yticklabels of the second graph take more room, which makes it look smaller than the first graph.
I specified the figsize as the same using the following code
fig, ax = plt.subplots(figsize=(6,4))
But obviously when other things like titles, labels, tick labels take more space, the "main plot" appears smaller, making two subfigures misaligned. Is there any way to specify the size of the "main plot" ignoring other labels, titles, etc.?
PS: I didn't use matplotlib's subplots function because I noticed a bug in pandas or matplotlib: whenever I use an inset axis, the xlabel and xticklabels will not show. So I have to get around this by plotting two figures respectively and include them as two subfigures in latex.
When I am faced with this situation, I simply hard code the axes placement on the figure, then things will line up...
import matplotlib.pyplot as plt
ax = plt.axes([0.15, 0.65, 0.8, 0.3])
ax.plot(range(100), range(100))
ax2 = plt.axes([0.15, 0.15, 0.8, 0.3])
ax2.plot(range(100), range(10000, 110000, 1000))
If you set the left
value of fig.subplots_adjust
to a constant for both plots, the left edges should be in the same place, eg:
fig.subplots_adjust(left = 0.12) # you might need to adjust 0.12 to your needs
Put that in your scripts for both your figures and that should align them both nicely.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.