1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

2軸を持つグラフ描画

1
Last updated at Posted at 2022-10-27

目的

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()

image.png
結果、期待通り表示された。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?