User Tools

Site Tools


python:matplotlib:線種の設定

Differences

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

Link to this comparison view

Next revision
Previous revision
python:matplotlib:線種の設定 [2018/01/22 18:06]
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 
 + 
 +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を消すと色は自動的に設定されます。 
 + 
 +===== ライン、マーカーと色の種類 ===== 
 + 
 +==== ラインの種類 ==== 
 + 
 +ラインの種類は次のとおり用意されています。
  
 <file python lines.py> <file python lines.py>
Line 26: Line 52:
 </file> </file>
  
 +{{:python:matplotlib:lines.png?direct&400|}}
  
-====== ポイントの種類 ======+==== マーカーの種類 ==== 
 + 
 +マーカーの種類は次のとおり用意されています。
  
 <file python points.py> <file python points.py>
Line 64: Line 93:
 plt.savefig("points.png") plt.savefig("points.png")
 </file> </file>
 +
 +{{:python:matplotlib:points.png?direct&400|}}
 +
 +==== 色の種類 ====
 +
 +|b|青 (Blue)|
 +|g|緑 (Green)|
 +|r|赤 (Red)|
 +|c|シアン (Cyan)|
 +|m|マゼンタ (Magenta)|
 +|y|黄 (Yellow)|
 +|k|黒 (Black)|
 +|w|白 (White)|
 +
 +
 +
 +
 +
 +
 +====== ラインの太さ ======
 +
 +線の太さはlinewidthあるいはlwで指定します。
 +
 +<file python>
 +plt.plot(x, y, "-", linewidth=2)
 +</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/線種の設定.1516611979.txt.gz · Last modified: 2021/06/27 21:59 (external edit)