User Tools

Site Tools


python:matplotlib:文字の設定

Differences

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

Link to this comparison view

python:matplotlib:文字の設定 [2018/01/21 20:08] – 作成 koudaipython:matplotlib:文字の設定 [2018/01/21 20:12] (current) – 削除 koudai
Line 1: Line 1:
-====== 概要 ====== 
  
-matplotlibで使われる文字の大きさやフォントの種類の設定方法を紹介します。 
- 
- 
- 
-====== まとめて設定 ====== 
- 
-グラフに登場するすべてのフォントを同じ大きさ、同じフォントにする場合は plt.rcParam を使うと便利です。 
- 
-<file python plot.py> 
-import numpy as np 
-import matplotlib.pyplot as plt 
- 
-plt.rcParams["font.family"] = "sans-serif"   # 使用するフォント 
-plt.rcParams["font.size"] = 20               # 文字の大きさ 
- 
-x = np.arange(-5,5,0.1) 
-y = np.sin(x) 
- 
-plt.title("graph") 
-plt.xlabel("x") 
-plt.ylabel("y") 
- 
-plt.plot(x, y, label="sin x") 
- 
-plt.legend(loc="lower left") 
- 
-plt.tick_params() 
-plt.tight_layout() 
- 
-plt.show() 
-</file> 
- 
- 
-====== 個別に設定 ====== 
- 
-フォントのサイズを個別に設定する場合は、各文字の出力のときに fontsize を指定します。 
- 
- 
-<file python plot.py> 
-import numpy as np 
-import matplotlib.pyplot as plt 
- 
-x = np.arange(-5,5,0.1) 
-y = np.sin(x) 
- 
-plt.title("graph", fontsize = 20) 
-plt.xlabel("x", fontsize = 20) 
-plt.ylabel("y", fontsize = 20) 
- 
-plt.plot(x, y, label="sin x") 
- 
-plt.legend(loc="lower left", fontsize = 20) 
- 
-plt.tick_params(labelsize = 20) 
-plt.tight_layout() 
- 
-plt.savefig("font.png") 
-</file> 
python/matplotlib/文字の設定.1516532918.txt.gz · Last modified: 2021/06/27 21:59 (external edit)