awips2/pythonPackages/matplotlib/doc/mpl_examples/api/fahrenheit_celcius_scales.py
root e2ecdcfe33 Initial revision of AWIPS2 11.9.0-7p5
Former-commit-id: a02aeb236c [formerly 9f19e3f712] [formerly a02aeb236c [formerly 9f19e3f712] [formerly 06a8b51d6d [formerly 64fa9254b946eae7e61bbc3f513b7c3696c4f54f]]]
Former-commit-id: 06a8b51d6d
Former-commit-id: 8e80217e59 [formerly 3360eb6c5f]
Former-commit-id: 377dcd10b9
2012-01-06 08:55:05 -06:00

28 lines
662 B
Python
Executable file

"""
Shoiw how to display two scales on the left and right y axis -- Fahrenheit and Celcius
"""
import matplotlib.pyplot as plt
fig = plt.figure()
ax1 = fig.add_subplot(111) # the Fahrenheit scale
ax2 = ax1.twinx() # the Celcius scale
def Tc(Tf):
return (5./9.)*(Tf-32)
def update_ax2(ax1):
y1, y2 = ax1.get_ylim()
ax2.set_ylim(Tc(y1), Tc(y2))
ax2.figure.canvas.draw()
# automatically update ylim of ax2 when ylim of ax1 changes.
ax1.callbacks.connect("ylim_changed", update_ax2)
ax1.plot([78, 79, 79, 77])
ax1.set_title('Two scales: Fahrenheit and Celcius')
ax1.set_ylabel('Fahrenheit')
ax2.set_ylabel('Celcius')
plt.show()