Issue
When pushing two plots together, I'd like to have the the ticks set to 'inout' and have it properly displayed over both the charts, but the 2nd chart is overlapping it.
import matplotlib.pyplot as plt
import numpy as np
t = np.arange(0.01, 5.0, 0.01)
s1 = np.sin(2 * np.pi * t)
s2 = np.exp(-t)
ax1 = plt.subplot(211)
plt.plot(t, s1)
plt.tick_params('x', labelbottom=False, direction='inout', length=6)
ax2 = plt.subplot(212, sharex=ax1)
plt.plot(t, s2)
plt.subplots_adjust(hspace=0)
plt.show()
We can adjust the hspace and see that they're there, but just getting covered.
I've tried changing the z-order, but that didn't work.
plt.tick_params('x', labelbottom=False, direction='inout', length=6, zorder=100)
Solution
IIUC, you can create ax2
before ax1
:
import matplotlib.pyplot as plt
import numpy as np
t = np.arange(0.01, 5.0, 0.01)
s1 = np.sin(2 * np.pi * t)
s2 = np.exp(-t)
ax2 = plt.subplot(212)
plt.plot(t, s2)
ax1 = plt.subplot(211, sharex=ax2)
plt.plot(t, s1)
plt.tick_params('x', labelbottom=False, direction='inout', length=6)
plt.subplots_adjust(hspace=0)
plt.show()
Output:
Answered By - Corralien
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.