目的
pythonで2軸を持つグラフの表示方法について確かめる
行う事
X軸を共有して2つのY軸を持つ図を作成するとき片方は、x軸が同じ連続値でなくても、
期待通り表示されるかどうか確認する。
##input file
test1.csv
ID value
0 1 1
1 2 2
2 3 3
3 4 4
4 5 5
5 6 6
6 7 7
7 8 8
8 9 9
9 10 10
test2.csv
ID value
0 1 10
1 5 5
2 10 1
コード
import matplotlib.pyplot as plt
import pandas as pd
test1 = pd.read_csv('test1.csv')
test2 = pd.read_csv('test2.csv')
print(test1)
print(test2)
fig = plt.figure()
ax1 = fig.add_subplot()
ax1.plot(test1['ID'], test1['value'], color='b')
ax2 = ax1.twinx()
ax2.plot(test2['ID'], test2['value'], color='r')
plt.show()
