two labels on one axis python 1

two labels on one axis python

import numpy as np
import matplotlib.pyplot as plt
from matplotlib import rc
rc('mathtext', default='regular')

fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(time, Swdown, '-', label = 'Swdown')
ax.plot(time, Rn, '-', label = 'Rn')
ax2 = ax.twinx()
ax2.plot(time, temp, '-r', label = 'temp')
ax.set_xlabel("Time (h)")
ax.set_ylabel(r"Radiation ($MJ\,m^{-2}\,d^{-1}$)")
ax2.set_ylabel(r"Temperature ($^\circ$C)")
ax2.set_ylim(0, 35)

Here is what the above code is Doing:
1. Create a figure object
2. Create an axis object
3. Plot the data on the axis object
4. Create a second axis object
5. Plot the data on the second axis object
6. Create a legend
7. Add gridlines
8. Add labels to the x and y axes
9. Set the limits of the y axis
10. Display the figure

Similar Posts