First page Back Continue Last page Overview Image

Multiple Y Axes

Let's add another axes to our city_frame. We will add a column with the population density, i.e. the number of people per square kilometre:

fig, ax = plt.subplots()

fig.suptitle("City Statistics")

ax.set_ylabel("Population")

ax.set_xlabel("Citites")

ax_area, ax_density = ax.twinx(), ax.twinx()

ax_area.set_ylabel("Area")

ax_density.set_ylabel("Density")

rspine = ax_density.spines['right']

rspine.set_position(('axes', 1.25))

ax_density.set_frame_on(True)

ax_density.patch.set_visible(False)

fig.subplots_adjust(right=0.75)