LoginSignup
1
0

More than 3 years have passed since last update.

MatplotLibでループして図を書き、あとからX軸を変更する

Posted at

目的

MatplotLibにてループでfigureを描く場合に、あとから軸を修正する方法を記述

動作環境

Python 3.7 (Anaconda) Spyder

方法

axesを保存しておいて、あとからaxes.set_xlim(start,end) で変更すれば、軸をあとから修正
できるらしい。
ウインドウが別枠で出ない場合は、コンソール上で %matplotlib qt と打つ

実行コード


import matplotlib.pyplot as plt
import numpy as np

plt.close('all')

#Make Data
Time =np.arange(0,1,0.001);
Data = np.sin(2*np.pi*10*Time);

#3回のループで3つのFigureを描画
fig = {}
ax ={}
for idx in range(1,4):
    fig[idx] = plt.figure()
    ax[idx]  = plt.subplot(311)
    plt.plot(Time, Data)

#2番目のfigureの軸を変更
ax[2].set_xlim(0,0.5)
plt.show()

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