開発環境
- macOS High Sierra - Apple
- Emacs (Text Editor)
- Python 3.6 (プログラミング言語)
Pythonからはじめる数学入門 (Amit Saha (著)、黒川 利明 (翻訳)、オライリージャパン)の2章(データをグラフで可視化する)、2.6(プログラミングチャレンジ)、問題2-1(1日の間に気温はどのように変化するか)を取り組んでみる。
コード(Emacs)
Python 3
#!/usr/bin/env python3
from matplotlib import pyplot as plt
times = [
'00:00 AM',
'01:00 AM',
'02:00 AM',
'03:00 AM',
'04:00 AM',
'05:00 AM',
'06:00 AM',
'07:00 AM'
]
temps1 = [
15,
17,
21,
25,
22,
18,
19,
18
]
temps2 = [
15,
13,
11,
10,
11,
14,
17,
17
]
plt.plot(times, temps1)
plt.plot(times, temps2)
plt.legend(['New York', 'Tokyo'])
plt.title('Weather')
plt.xlabel('time')
plt.ylabel('temperature')
plt.savefig('sample1.svg')
入出力結果(Terminal, Jupyter(IPython))
$ ./sample1.py $
0 コメント:
コメントを投稿