天天看點

matplotlib折線圖(一圖多個坐标系子圖)

代碼示例:

import matplotlib.pyplot as plt
import numpy as np

x = np.arange(1,100)
fig = plt.figure(figsize=(20,10),dpi=80)
# 建立子圖1
sub1 = fig.add_subplot(2,2,1)
sub1.plot(x,x)

#建立子圖2
sub2 = fig.add_subplot(2,2,2)
sub2.plot(x,x**2)
sub2.grid(color='r',linestyle='--',linewidth=3,alpha=0.2)

#建立子圖3
sub3 = fig.add_subplot(2,2,3)
sub3.plot(x,np.log(x))

#建立子圖4
sub4 = fig.add_subplot(2,2,4)
sub4.plot(x,np.log(x)*x)

plt.show
           

效果截圖:

matplotlib折線圖(一圖多個坐标系子圖)

繼續閱讀