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 Both sides next revision
python:matplotlib:基本的な使い方 [2018/01/20 23:06]
koudai
python:matplotlib:基本的な使い方 [2018/01/20 23:17]
koudai
Line 115: Line 115:
 (右下の場合は lower right とします。他も同様) (右下の場合は lower right とします。他も同様)
  
 +
 +===== プロット範囲の指定 =====
 +
 +matplotlibでは、そのままプロットするとすべてのデータが枠内に収まるようにプロットされます。
 +プロットしたい範囲を制限する場合は次のようにします。
 +
 +<file python sin.py>
 +import numpy as np
 +import matplotlib.pyplot as plt
 +
 +x = np.arange(-2.0 * np.pi, 2.0 * np.pi, 0.1)  # -2πから2πまでのxを用意 
 +y1 = np.sin(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.ylim(-1.2,   1.2)     # y軸は-1.2から1.2まで
 +
 +plt.show()
 +</file>
 +
 +{{:python:matplotlib:intro4.png?direct&200|}}
  
  
python/matplotlib/基本的な使い方.txt · Last modified: 2021/06/27 22:04 (external edit)