python:matplotlib:線種の設定
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| python:matplotlib:線種の設定 [2018/01/22 18:19] – [基本的な使い方] koudai | python:matplotlib:線種の設定 [2021/06/27 22:04] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 6: | Line 6: | ||
| ====== 基本的な使い方 ====== | ====== 基本的な使い方 ====== | ||
| - | 例えば、赤色の実線で●形のポイントをつなぎたい場合は< | + | 例えば、赤色の実線で●形のマーカーをつなぎたい場合は< |
| - | -orは、左から「実線」「●形のポイント」「赤色」を意味します。 | + | -orは、左から「実線」「●形のマーカー」「赤色」を意味します。 |
| + | 指定する順番は任意です。 | ||
| <file python line.py> | <file python line.py> | ||
| Line 21: | Line 22: | ||
| </ | </ | ||
| + | {{: | ||
| - | ポイントがいらない場合は、oを消して-rとすれば赤色の実線になります。 | + | マーカーがいらない場合は、oを消して-rとすれば赤色の実線になります。 |
| またrを消すと色は自動的に設定されます。 | またrを消すと色は自動的に設定されます。 | ||
| - | ====== ラインとポイントの種類 | + | ===== ライン、マーカーと色の種類 ===== |
| - | + | ==== ラインの種類 ==== | |
| - | ===== ラインの種類 | + | |
| ラインの種類は次のとおり用意されています。 | ラインの種類は次のとおり用意されています。 | ||
| Line 51: | Line 52: | ||
| </ | </ | ||
| + | {{: | ||
| - | ===== ポイントの種類 | + | ==== マーカーの種類 ==== |
| - | ポイントの種類は次のとおり用意されています。 | + | マーカーの種類は次のとおり用意されています。 |
| <file python points.py> | <file python points.py> | ||
| Line 92: | Line 94: | ||
| </ | </ | ||
| - | ===== ラインとポイントの組み合わせ ===== | + | {{: |
| - | ラインとポイントを同時に指定することで、両方が描けます。 | + | ==== 色の種類 ==== |
| - | <file python linespoints.py> | + | |b|青 (Blue)| |
| - | import numpy as np | + | |g|緑 (Green)| |
| - | import matplotlib.pyplot as plt | + | |r|赤 (Red)| |
| + | |c|シアン (Cyan)| | ||
| + | |m|マゼンタ (Magenta)| | ||
| + | |y|黄 (Yellow)| | ||
| + | |k|黒 (Black)| | ||
| + | |w|白 (White)| | ||
| - | x = np.arange(-5, | ||
| - | y = np.sin(x) | ||
| - | plt.plot(x, | ||
| - | plt.savefig("linespoints.png") | + | |
| + | |||
| + | |||
| + | ====== ラインの太さ ====== | ||
| + | |||
| + | 線の太さはlinewidthあるいはlwで指定します。 | ||
| + | |||
| + | <file python> | ||
| + | plt.plot(x, y, "-", linewidth=2) | ||
| </ | </ | ||
| + | |||
| + | |||
| + | ====== マーカーの大きさ ====== | ||
| + | |||
| + | マーカーの大きさはmarkersizeあるいはmsで指定します。 | ||
| + | |||
| + | <file python> | ||
| + | plt.plot(x, y, " | ||
| + | </ | ||
| + | |||
| + | |||
| + | ====== 色 ====== | ||
| + | |||
| + | 色を細かく指定する場合は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) | ||
| + | </ | ||
| + | |||
| + | |||
| + | |||
| + | ======= 参考 ======= | ||
| + | |||
| + | * http:// | ||
| + | * plt.plotのすべての機能について解説しています。 | ||
| + | |||
python/matplotlib/線種の設定.1516612799.txt.gz · Last modified: 2021/06/27 21:59 (external edit)
