forked from tdamdouni/Pythonista
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot-x-y.py
37 lines (25 loc) · 909 Bytes
/
plot-x-y.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# coding: utf-8
# http://www.omz-software.de/pythonista/docs/matplotlib/examples/api/fahrenheit_celsius_scales.html
# https://forum.omz-software.com/topic/2965/matplotlib-twins-does-not-function
"""
Show how to display two scales on the left and right y axis -- Fahrenheit and Celsius
"""
import matplotlib.pyplot as plt
fig, ax1 = plt.subplots() # ax1 is the Fahrenheit scale
ax2 = ax1.twinx() # ax2 is the Celsius 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 Celsius')
ax1.set_ylabel('Fahrenheit')
ax2.set_ylabel('Celsius')
plt.show()
# Resolved:
# ax2 = ax1.twinx()
# ax2.set_ylim(ax.get_ylim())