(Python3.6.8 Shellを用いています)
入力するデータファイル(plot_graph_data.txt)を、
1 1.1
2 1.2
3 1.6
としてデータを読み込み、次のグラフを作成したいと考えています。(Hello Helloの描画は除く)
次のようなプログラムを書きましたが、
下図の実行結果のようにx軸,y軸の範囲が目的のグラフと異なる結果になってしまいました。
原因を教えてくださいm(_)m
自分の書いたプログラム
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
x=[]
y=[]
fp = open('plot_graph_data.txt','r')
for i, line in enumerate(fp):
data=line.split()
x.append(data[0])
y.append(data[1])
ax.plot(x, y, 'ro') # red circle
ax.set_title("My graph", loc="center")
ax.set_xlabel("time(s)", labelpad=None)
ax.set_ylabel("height(m)", labelpad=None)
ax.set_xlim(left=0.0, right=4.0)
ax.set_ylim(bottom=0.0, top=2.0)
plt.show()