3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

PythonのMatplotlib のpyplot.scatterを使って散布図を書いてみた

Last updated at Posted at 2018-12-17

散布図を書いてみたので、超基本的なところのまとめ

環境

  • Windows10
  • Anaconda3-5.2.0
  • Python 3.6.5
  • JupyterNotebook

データセット(2018.csv)の一部

順位 チーム 試合 打率 打点 平均 安打
1 レッドソックス 162 0.268 876 5.41 1509
2 カブス 162 0.259 760 4.69 1450
3 インディアンズ 162 0.259 818 5.05 1448

用いたデータセットは2018年のMLBのチーム打撃成績です。実際は30チーム分のデータセットがあります。

必要なライブラリのインポート


import pandas as pd #pandasのimport
import matplotlib.pyplot as plt #matplotlibのimport

散布図を書いてみる

「順位」と「安打」のカラムを用いて散布図を書いてみます。


m18 = pd.read_csv("2018.csv") #pandasを使ってcsvを取り込む(上記のデータセット)
plt.scatter(m18["順位"],m18["安打"]) #plt.scatter(m_18["x座標のカラム"],m_18["y座標のカラム"]) 

散布図は matplotlibpyplot.scatter メソッドを利用して描く。基本的に、x 座標と y 座標を代入するだけ作成できる。

実行結果

1.png

x軸とy軸のラベルを付ける

plt.scatter(m18["順位"],m18["安打"])
plt.ylabel("hit") #y軸のラベルを付ける
plt.xlabel("rank") #x軸のラベルを付ける

実行結果

2.png

3
1
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
3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?