0
0

More than 3 years have passed since last update.

Python3 データをプロットすると軸の範囲が変化してしまいます

Last updated at Posted at 2020-04-04

(Python3.6.8 Shellを用いています)

入力するデータファイル(plot_graph_data.txt)を、
1 1.1
2 1.2
3 1.6
としてデータを読み込み、次のグラフを作成したいと考えています。(Hello Helloの描画は除く)

2020-04-04 180949.png

次のようなプログラムを書きましたが、
下図の実行結果のように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()

実行結果
Figure_1.png

0
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
0
0