LoginSignup
0
0

More than 5 years have passed since last update.

折れ線グラフ

Posted at

折れ線グラフ

「ニューヨークの大気状態観測値」を例に説明します。

# 「#」(シャープ)以降の文字はプログラムに影響しません。
# 図やグラフを図示するためのライブラリをインポートする。
import matplotlib.pyplot as plt
%matplotlib inline
# データフレーム操作に関するライブラリをインポートする
import pandas as pd
from pandas.tools import plotting # 高度なプロットを行うツールのインポート
# URL によるリソースへのアクセスを提供するライブラリをインポートする。
# import urllib # Python 2 の場合
import urllib.request # Python 3 の場合
# ウェブ上のリソースを指定する
url = 'https://raw.githubusercontent.com/maskot1977/ipython_notebook/master/toydata/airquality.txt'
# 指定したURLからリソースをダウンロードし、名前をつける。
# urllib.urlretrieve(url, 'airquality.txt') # Python 2 の場合
urllib.request.urlretrieve(url, 'airquality.txt') # Python 3 の場合
# データの読み込み
df1 = pd.read_csv('airquality.txt', sep='\t', index_col=0) 
df1
# 折れ線グラフを作成する
df1.plot()
# 左側4列だけを用いて折れ線グラフを作成する
df1.iloc[:, 0:4].plot()
# 折れ線グラフの描き方(別法)
plt.figure(figsize=(8, 8))

plt.subplot(4, 1, 1)
plt.plot(df1.iloc[:, 0])
plt.xticks([])
plt.ylabel(df1.columns[0])

plt.subplot(4, 1, 2)
plt.plot(df1.iloc[:, 1])
plt.xticks([])
plt.ylabel(df1.columns[1])

plt.subplot(4, 1, 3)
plt.plot(df1.iloc[:, 2])
plt.xticks([])
plt.ylabel(df1.columns[2])

plt.subplot(4, 1, 4)
plt.plot(df1.iloc[:, 3])
plt.xticks(rotation=90)
plt.ylabel(df1.columns[3])
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