To create two y-axes and set the ticks for each, you can use the following code. This example customizes this answer. It also uses a function from the official reference, so please refer to it.
import matplotlib.pyplot as plt
from matplotlib.ticker import MultipleLocator
def make_patch_spines_invisible(ax):
ax.set_frame_on(True)
ax.patch.set_visible(False)
for sp in ax.spines.values():
sp.set_visible(False)
fig, ax1 = plt.subplots(figsize=(4,9))
fig.subplots_adjust(right=0.75)
x = 1
y = 1
ax2 = ax1.twinx()
ax1.scatter(x,y)
ax1.set_yticks(df.depth)
ax1.yaxis.set_minor_locator(MultipleLocator(0.5))
ax1.set_ylabel('depth')
ax1.spines['top'].set_visible(False)
ax1.spines['right'].set_visible(False)
ax2.set_yticks(df['mean'])
ax2.spines["left"].set_position(("axes", -0.3))
ax2.set_ylabel('mean')
make_patch_spines_invisible(ax2)
ax2.spines["left"].set_visible(True)
ax2.yaxis.set_label_position('left')
ax2.yaxis.set_ticks_position('left')
plt.show()
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…