This shows you the differences between two versions of the page.
python:matplotlib:線種の設定 [2018/01/22 18:33] koudai |
python:matplotlib:線種の設定 [2021/06/27 22:04] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== 概要 ====== | ||
- | matplotlibのラインやポイントをいろいろ変更します。 | ||
- | |||
- | |||
- | ====== 基本的な使い方 ====== | ||
- | |||
- | 例えば、赤色の実線で●形のポイントをつなぎたい場合は< | ||
- | -orは、左から「実線」「●形のポイント」「赤色」を意味します。 | ||
- | |||
- | <file python line.py> | ||
- | import numpy as np | ||
- | import matplotlib.pyplot as plt | ||
- | |||
- | x = np.arange(-5, | ||
- | y = np.sin(x) | ||
- | |||
- | plt.plot(x, y, " | ||
- | |||
- | plt.savefig(" | ||
- | </ | ||
- | |||
- | |||
- | ポイントがいらない場合は、oを消して-rとすれば赤色の実線になります。 | ||
- | またrを消すと色は自動的に設定されます。 | ||
- | |||
- | ====== ライン、ポイントと色の種類 ====== | ||
- | |||
- | ===== ラインの種類 ===== | ||
- | |||
- | ラインの種類は次のとおり用意されています。 | ||
- | |||
- | <file python lines.py> | ||
- | import numpy as np | ||
- | import matplotlib.pyplot as plt | ||
- | |||
- | x = np.arange(-5, | ||
- | y = np.sin(x) | ||
- | |||
- | plt.plot(x, | ||
- | plt.plot(x+0.2, | ||
- | plt.plot(x+0.4, | ||
- | plt.plot(x+0.6, | ||
- | |||
- | plt.legend() | ||
- | |||
- | plt.xlim(-np.pi, | ||
- | |||
- | plt.savefig(" | ||
- | </ | ||
- | |||
- | |||
- | ===== ポイントの種類 ===== | ||
- | |||
- | ポイントの種類は次のとおり用意されています。 | ||
- | |||
- | <file python points.py> | ||
- | import numpy as np | ||
- | import matplotlib.pyplot as plt | ||
- | |||
- | x = np.arange(0, | ||
- | |||
- | plt.plot(x, x, " | ||
- | plt.plot(x+1, | ||
- | plt.plot(x+2, | ||
- | plt.plot(x+3, | ||
- | plt.plot(x+4, | ||
- | plt.plot(x+5, | ||
- | plt.plot(x+6, | ||
- | plt.plot(x+7, | ||
- | plt.plot(x+8, | ||
- | plt.plot(x+9, | ||
- | plt.plot(x+10, | ||
- | plt.plot(x+11, | ||
- | plt.plot(x+12, | ||
- | plt.plot(x+13, | ||
- | plt.plot(x+14, | ||
- | plt.plot(x+15, | ||
- | plt.plot(x+16, | ||
- | plt.plot(x+17, | ||
- | plt.plot(x+18, | ||
- | plt.plot(x+19, | ||
- | plt.plot(x+20, | ||
- | |||
- | plt.legend(fontsize=8) | ||
- | |||
- | plt.xlim(0, 30) | ||
- | plt.ylim(0, 10) | ||
- | |||
- | plt.savefig(" | ||
- | </ | ||
- | |||
- | ===== 色の種類 ===== | ||
- | |||
- | |b|青 (Blue)| | ||
- | |g|緑 (Green)| | ||
- | |r|赤 (Red)| | ||
- | |c|シアン (Cyan)| | ||
- | |m|マゼンタ (Magenta)| | ||
- | |y|黄 (Yellow)| | ||
- | |k|黒 (Black)| | ||
- | |w|白 (White)| | ||
- | |||
- | |||
- | ====== 線の太さ ====== | ||
- | |||
- | 線の太さはlinewidthあるいはlwで指定します。 | ||
- | <file python> | ||
- | |||
- | |||
- | ====== 細かい色の設定 ====== | ||
- | |||
- | 色を細かく指定する場合はcolorあるいはcで指定します。 | ||
- | |||
- | ===== 色の名称による指定 ===== | ||
- | |||
- | <file python> | ||
- | plt.plot(x, y, color=" | ||
- | </ | ||
- | |||
- | 使用できる色の名前は以下のページで参照してください。 | ||
- | * https:// | ||
- | |||
- | ===== 16進数のカラーコードによる指定 ===== | ||
- | |||
- | <file python> | ||
- | plt.plot(x, y, color="# | ||
- | </ | ||
- | |||
- | ===== RGBによる指定 ===== | ||
- | |||
- | 3成分の配列に赤、緑、青の重みを指定します。 | ||
- | |||
- | <file python> | ||
- | plt.plot(x, y, color=[1.0, 0.0, 0.0]) | ||
- | </ | ||
- | |||
- | |||
- | ====== グレースケールによる指定 ====== | ||
- | |||
- | 0(白)から1(黒)までで指定します。 | ||
- | <file python> | ||
- | plt.plot(x, y, color=0.5) | ||
- | </ |