Since Steve Tjoa's answer always pops up first and mostly lonely when I search for multiple y-axes at Google, I decided to add a slightly modified version of his answer. This is the approach from this matplotlib example.
Reasons:
- His modules sometimes fail for me in unknown circumstances and cryptic intern errors.
- I don't like to load exotic modules I don't know (
mpl_toolkits.axisartist
, mpl_toolkits.axes_grid1
).
- The code below contains more explicit commands of problems people often stumble over (like single legend for multiple axes, using viridis, ...) rather than implicit behavior.

import matplotlib.pyplot as plt
# Create figure and subplot manually
# fig = plt.figure()
# host = fig.add_subplot(111)
# More versatile wrapper
fig, host = plt.subplots(figsize=(8,5), layout='constrained') # (width, height) in inches
# (see https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.subplots.html and
# .. https://matplotlib.org/stable/tutorials/intermediate/constrainedlayout_guide.html)
ax2 = host.twinx()
ax3 = host.twinx()
host.set_xlim(0, 2)
host.set_ylim(0, 2)
ax2.set_ylim(0, 4)
ax3.set_ylim(1, 65)
host.set_xlabel("Distance")
host.set_ylabel("Density")
ax2.set_ylabel("Temperature")
ax3.set_ylabel("Velocity")
color1, color2, color3 = plt.cm.viridis([0, .5, .9])
p1 = host.plot([0, 1, 2], [0, 1, 2], color=color1, label="Density")
p2 = ax2.plot( [0, 1, 2], [0, 3, 2], color=color2, label="Temperature")
p3 = ax3.plot( [0, 1, 2], [50, 30, 15], color=color3, label="Velocity")
host.legend(handles=p1+p2+p3, loc='best')
# right, left, top, bottom
ax3.spines['right'].set_position(('outward', 60))
# no x-ticks
host.xaxis.set_ticks([])
# Alternatively (more verbose):
# host.tick_params(
# axis='x', # changes apply to the x-axis
# which='both', # both major and minor ticks are affected
# bottom=False, # ticks along the bottom edge are off)
# labelbottom=False) # labels along the bottom edge are off
# sometimes handy: direction='in'
# Move "Velocity"-axis to the left
# ax3.spines['left'].set_position(('outward', 60))
# ax3.spines['left'].set_visible(True)
# ax3.spines['right'].set_visible(False)
# ax3.yaxis.set_label_position('left')
# ax3.yaxis.set_ticks_position('left')
host.yaxis.label.set_color(p1[0].get_color())
ax2.yaxis.label.set_color(p2[0].get_color())
ax3.yaxis.label.set_color(p3[0].get_color())
# For professional typesetting, e.g. LaTeX, use .pgf or .pdf
# For raster graphics use the dpi argument. E.g. '[...].png", dpi=300)'
plt.savefig("pyplot_multiple_y-axis.pdf", bbox_inches='tight')
# bbox_inches='tight': Try to strip excess whitespace
# https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.savefig.html