0
0

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 3 years have passed since last update.

Matplotlib メモ

Last updated at Posted at 2020-10-03

(1)準備

matplotlibをインストール
seabornもインストールする(今回seabornは使わない)

pip install matplotlib
pip install seaborn

matplotlib、seabornともに日本語化も行う
matplotlibとseabornの日本語化は以下のサイトを参考にした
https://qiita.com/Masahiro_T/items/cfe1a016a4f0db5df760

iPAフォント上記サイトでiPAフォントは以下のサイトのゴシックをダウンロード
IPAゴシック(Ver.003.03)
ipag00303.zip(4.09 MB)
https://moji.or.jp/ipafont/ipa00303/

import pandas as pd
import numpy as np
from matplotlib import pyplot as plt
%matplotlib inline #jupyternotebookを使用する場合必要
import seaborn as sns

x1 = [10 ,20 ,30,40,50 ,60 ,70 ,80,90,100]
y1 = [120,100,20,40,100,130,120,34,56,33]
x2 = [10 ,30 ,40,60,70 ,80 ,110 ,115,117,120]
y2 = [20,100,120,20,50,60,20,84,36,53]

※日本語化補足

以下のようにjapanize-matplotlibをインストールする手法もある

pip install japanize-matplotlib
import japanize_matplotlib

(2)折れ線グラフを書く

.py
# markerの詳細は、https://pythondatascience.plavox.info/matplotlib/マーカーの名前
# colorの詳細は、https://pythondatascience.plavox.info/matplotlib/色の名前
plt.plot(x1, y1, color = 'red', marker = '.')
plt.show()

(3)サイズ変更、出力

.py
# 大きいサイズにする
# pngでセーブする
plt.figure(figsize=(14, 4), dpi=50)
plt.plot(x1, y1, color = 'blue', marker = '.')
plt.savefig("bar_basic.png")
put.show()

(4)タイトルをつける

.py
# グラフにタイトルをつける
plt.title("テスト")
plt.plot(x1, y1, color = 'red', marker = '.')
plt.show()

(5)グリッド線、x軸y軸にラベルをつける

.py
 #グリッド線をつける
plt.grid()
plt.xlabel('X軸ラベル')
plt.ylabel('Y軸ラベル')
plt.title("テスト")
plt.plot(x1, y1, color = 'red', marker = '.')

(6)複数のグラフ

.py
# 複数のグラフを重ねる
# グリッド線をつける
plt.grid()
plt.xlabel('X軸ラベル')
plt.ylabel('Y軸ラベル')
plt.title("テスト")
plt.plot(x1, y1, color = 'red', marker = '.',label="Aパターン")
plt.plot(x2, y2, color = 'blue', marker = '.',label="Bパターン")
plt.legend()
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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?