LoginSignup
32
31

More than 5 years have passed since last update.

pyplotで2軸のグラフを描画する方法

Last updated at Posted at 2017-06-16

スクリプト

  • 2つのプロットを比較したい
  • y軸のスケールが異なるので片方が潰れてしまって見えない
  • そんな時のおまじない
dual_plot.py
import matplotlib.pyplot as plt

fig, ax1 = plt.subplots()
ax1.plot(data1)
ax2 = ax1.twinx()  # 2つのプロットを関連付ける
ax2.plot(data2)
plt.show()

計算結果の例

  • ピークの位置とステップの位置が重なっていて気持ちいい

figure_1.png

32
31
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
32
31