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
Next revision Both sides next revision
python:matplotlib:基本的な使い方 [2018/01/21 00:30]
koudai [ラベルの作成]
python:matplotlib:基本的な使い方 [2018/01/22 20:13]
koudai [グラフの表示範囲の指定]
Line 29: Line 29:
 {{:python:matplotlib:intro1.png?direct&400|}} {{:python:matplotlib:intro1.png?direct&400|}}
  
-保存するにはグラフが表示されたウィンドウの上の方にあるフロッピーディスクのマークをクリックします(Ctrlキーを押しながらsを押すのでも可)。 +保存するにはグラフが表示されたウィンドウの上の方にあるフロッピーディスクのマークをクリックします([Ctrl-s]も可)。
- +
-あるいはplt.savefigを使うとファイルに直接出力できます。 +
- +
-<file python> +
-import numpy as np +
-import matplotlib.pyplot as plt +
- +
-x = np.arange(-5, 5, 0.1) +
-y = np.sin(x) +
- +
-plt.plot(x, y) +
-plt.savefig("sin.png"  # プロットしたグラフをファイルsin.pngに保存する +
-</file> +
- +
-保存できる形式は +
-  * emf +
-  * eps +
-  * jpeg +
-  * jpg +
-  * pdf +
-  * png +
-  * ps +
-  * raw +
-  * rgba +
-  * svg +
-  * svgz +
-  * tif +
-  * tiff +
-です。 +
-ファイルの種類は拡張子により自動判別されます+
  
  
Line 74: Line 44:
 y1 = np.sin(x) y1 = np.sin(x)
 y2 = np.cos(x) y2 = np.cos(x)
- 
-plt.title("graph") 
-plt.xlabel("x") 
-plt.ylabel("y") 
- 
-plt.plot(x, y1, label="sin x") 
-plt.plot(x, y2, label="cos x") 
-plt.legend() 
  
 plt.xlim(-np.pi, np.pi)   # x軸は-πからπまで plt.xlim(-np.pi, np.pi)   # x軸は-πからπまで
Line 167: Line 129:
 import matplotlib.pyplot as plt import matplotlib.pyplot as plt
  
-x = [1,2,3,4,5,6,7,8,9,10]         # データのx成分 +x = [1,2,3, 4, 5, 6, 7, 8, 9, 10]   # データのx成分 
-y = [1,4,9,16,25,36,49,64,81,100]  # データのy成分+y = [1,4,9,16,25,36,49,64,81,100]   # データのy成分
  
 plt.title("graph") plt.title("graph")
python/matplotlib/基本的な使い方.txt · Last modified: 2021/06/27 22:04 (external edit)