User Tools

Site Tools


python:matplotlib:線種の設定

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
python:matplotlib:線種の設定 [2018/01/22 18:10]
koudai [ポイントの種類]
python:matplotlib:線種の設定 [2021/06/27 22:04] (current)
Line 4: Line 4:
  
  
-====== ラインとポイントの種類 ======+====== 基本的な使い方 ======
  
 +例えば、赤色の実線で●形のマーカーをつなぎたい場合は<file python>plt.plot(x, y, "-or")</file>とします。
 +-orは、左から「実線」「●形のマーカー」「赤色」を意味します。
 +指定する順番は任意です。
  
-===== ラインの種類 =====+<file python line.py> 
 +import numpy as np 
 +import matplotlib.pyplot as plt 
 + 
 +x = np.arange(-5, 5, 0.2) 
 +y = np.sin(x) 
 + 
 +plt.plot(x, y, "-or"
 + 
 +plt.savefig("line.png"
 +</file> 
 + 
 +{{:python:matplotlib:line.png?direct&400|}} 
 + 
 +マーカーがいらない場合は、oを消して-rとすれば赤色の実線になります。 
 +またrを消すと色は自動的に設定されます。 
 + 
 +===== ライン、マーカーと色の種類 ===== 
 + 
 +==== ラインの種類 ====
  
 ラインの種類は次のとおり用意されています。 ラインの種類は次のとおり用意されています。
Line 30: Line 52:
 </file> </file>
  
 +{{:python:matplotlib:lines.png?direct&400|}}
  
-===== ポイントの種類 =====+==== マーカーの種類 ====
  
-ポイントの種類は次のとおり用意されています。+マーカーの種類は次のとおり用意されています。
  
 <file python points.py> <file python points.py>
Line 71: Line 94:
 </file> </file>
  
-===== ラインとポイントの組み合わせ =====+{{:python:matplotlib:points.png?direct&400|}}
  
-ラインとポイントを同時に指定することで、両方が描けます。+==== 色の種類 ====
  
-<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, 5, 0.2) 
-y = np.sin(x) 
  
-plt.plot(x,     y, "-o") 
  
-plt.savefig("linespoints.png")+ 
 + 
 + 
 +====== ラインの太さ ====== 
 + 
 +線の太さはlinewidthあるいはlwで指定します。 
 + 
 +<file python> 
 +plt.plot(x, y, "-", linewidth=2)
 </file> </file>
 +
 +
 +====== マーカーの大きさ ======
 +
 +マーカーの大きさはmarkersizeあるいはmsで指定します。
 +
 +<file python>
 +plt.plot(x, y, "o", markersize=8)
 +</file>
 +
 +
 +====== 色 ======
 +
 +色を細かく指定する場合はcolorあるいはcで指定します。
 +
 +===== 色の名称による指定 =====
 +
 +<file python>
 +plt.plot(x, y, color="red")
 +</file>
 +
 +使用できる色の名前は以下のページで参照してください。
 +  * https://matplotlib.org/examples/color/named_colors.html
 +
 +===== 16進数のカラーコードによる指定 =====
 +
 +<file python>
 +plt.plot(x, y, color="#ff0000"
 +</file>
 +
 +===== RGBによる指定 =====
 +
 +3成分の配列に赤、緑、青の重みを指定します。
 +
 +<file python>
 +plt.plot(x, y, color=[1.0, 0.0, 0.0])
 +</file>
 +
 +
 +===== グレースケールによる指定 =====
 +
 +0(白)から1(黒)までで指定します。
 +<file python>
 +plt.plot(x, y, color=0.5)
 +</file>
 +
 +
 +
 +======= 参考 =======
 +
 +  * http://own-search-and-study.xyz/2016/08/08/matplotlib-pyplot%E3%81%AEplot%E3%81%AE%E5%85%A8%E5%BC%95%E6%95%B0%E3%82%92%E4%BD%BF%E3%81%84%E3%81%93%E3%81%AA%E3%81%99/
 +    * plt.plotのすべての機能について解説しています。
 +
python/matplotlib/線種の設定.1516612235.txt.gz · Last modified: 2021/06/27 21:59 (external edit)