2
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

折れ線グラフ

Last updated at Posted at 2021-03-13

matplotlib

import numpy as np
import matplotlib.pyplot as plt

# 折れ線グラフ
x = np.array([0,1,2,3,4,5,6,7,8,9])
y = np.array([2,3,4,3,5,4,6,7,4,8])

plt.plot(x,y, color ="black")
plt.title("lineplot")
plt.xlabel("x")
plt.ylabel("y")
plt.savefig("折れ線グラフ") # 保存
plt.show()

download.png

seaborn+matplotlib

import seaborn as sns
sns.set() # グラフのデザインが変わる
plt.plot(x,y, color ="black")
plt.title("lineplot seaborn")
plt.xlabel("x")
plt.ylabel("y")
plt.show()

download-1.png

seaborn

sns.lineplot(x, y)
plt.show()

download-2.png

おまけ:plotを使って放物線を書く

plotを使って折れ線だけでなく、曲線も書ける。

$ y = 2x^2+1 $ の放物線を描画
$x$には指定した区間で連続する数列(np.linspaceで作る)
$y$には二次関数数の式

import matplotlib.pyplot as plt

plt.figure(figsize=(6,4))
x = np.linspace(-2,2)
y = 2*x**2+1 # この二次関数に乗せる
plt.plot(x, y)

download-4.png

2
7
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?