matplotlib畫折線圖和點分佈圖
阿新 • • 發佈:2019-01-06
matplotlib畫圖
1點分佈圖
import numpy as np
import matplotlib.pyplot as plt
#資料
x_num=np.array(np.arange(15))
y_num=10*x_num+20*np.random.random(15)
fig = plt.figure()
# 畫圖(點圖)
# fig, ax = plt.subplots()
ax = fig.add_subplot(3,2,1)
ax.scatter(x_num, y_num)
ax.set_xlabel('x')
ax.set_ylabel(' y')
plt.show()
2折線圖
import numpy as np
import matplotlib.pyplot as plt
#資料
x_num=np.array(np.arange(15))
y_num=10*x_num+20*np.random.random(15)
fig = plt.figure()
# 畫圖(點圖)
# fig, ax = plt.subplots()
ax = fig.add_subplot(3,2,1)
ax.plot(x_num, y_num)
ax.set_xlabel('x')
ax.set_ylabel(' y')
plt.show()
3畫多個圖
#coding=utf-8 ''' Created on 2018年6月12日 @author: lzs ''' import numpy as np import matplotlib.pyplot as plt #資料 x_num=np.array(np.arange(15)) y_num=10*x_num+20*np.random.random(15) fig = plt.figure() ax = fig.add_subplot(3,2,1) ax1 = fig.add_subplot(3,2,2) # 畫圖(點圖) # fig, ax = plt.subplots() # ax ax.scatter(x_num, y_num) ax.set_xlabel('x') ax.set_ylabel(' y') # ax1 ax1.plot(x_num, y_num) ax1.set_xlabel('x') ax1.set_ylabel(' y') plt.show()