Python經典畫圖模版:散點圖、平滑曲線圖、分段曲線圖、雷達圖

在這裏插入圖片描述

一、最簡單的模版(曲線、散點)。

import matplotlib.pyplot as plt
plt.plot([1,2,3,4])
plt.ylabel('some numbers')
plt.show()

在這裏插入圖片描述

import matplotlib.pyplot as plt
plt.plot([1,2,3,4], [1,4,9,16], 'ro')#x=[1,2,3,4],y=[1,4,9,16],'ro'表示紅色的圓點
#axis接收的list參數表示:[xmin, xmax, ymin, ymax] 
plt.axis([0, 6, 0, 20])#設置x、y軸的長度,x軸爲[0,6],y軸爲[0,20]
plt.show()

在這裏插入圖片描述

import numpy as np
import matplotlib.pyplot as plt
# 以0.2爲間隔均勻採樣
t = np.arange(0., 5., 0.2)
#查看t的值

# 'r--':紅色的需要;'bs':藍色方塊;'g^':綠色三角
plt.plot(t, t, 'r--', t, t**2, 'bs', t, t**3, 'g^')
plt.show()

在這裏插入圖片描述

二、微微複雜的模版,需要自己填寫列表數據,注意x軸與y軸數據個數要相同

import numpy as np
from matplotlib import pyplot as plt
from scipy.interpolate import make_interp_spline

font1 = {'family' : 'DejaVu Sans',
'weight' : 'normal',
'size'   : 20,
}

x = np.array([0, 12,25, 36,50,62,75,84,100])
y = np.array([999.84,999.5, 997.05, 993.69,988.04,982.16,974.24,969.26,958.36])
x_smooth = np.linspace(x.min(), x.max(), 300)
y_smooth = make_interp_spline(x, y)(x_smooth)
plt.xlabel(u'T/℃',font1)#fill the meaning of X axis
plt.ylabel(u'ρ/kg*m-3',font1)#fill the meaning of Y axis
plt.title(u'T-ρ',font1)#add the title of the figure
plt.plot(x_smooth, y_smooth)
plt.show()

在這裏插入圖片描述

import numpy as np
import matplotlib.pyplot as plt
t1 = np.arange(0., 0.2232, 0.001)
plt.plot(t1,t1*0.04*999.84/0.0017921,label='T=0℃');
plt.plot(t1,t1*0.04*997.05/0.00089008,label='T=25℃');
plt.plot(t1,t1*0.04*988.04/0.0005464,label='T=50℃');
plt.plot(t1,t1*0.04*974.24/0.000376,label='T=75℃');
plt.plot(t1,t1*0.04*958.36/0.0002838,label='T=100℃');
#plt.plot(t,t**3,'r--',label='y=t^3');
#plt.plot(t, t, 'r--', t, t**2, 'bs', t, t**3, 'g^')

font1 = {'family' : 'Times New Roman',
'weight' : 'normal',
'size'   : 20,
}

plt.xlabel(u'u/(m/s)',font1)#fill the meaning of X axis
plt.ylabel(u'Re',font1)#fill the meaning of Y axis
plt.title(u'Re-u',font1)#add the title of the figure
plt.legend()

在這裏插入圖片描述

三、需要分段的曲線圖

import numpy as np
import matplotlib.pyplot as plt
t1 = np.arange(0., 0.0893, 0.001)
t2 = np.arange(0.0893,0.2232,0.001)
t3 = np.arange(0.2233,0.4,0.001)
plt.plot(t1,t1*0.00089008*1.15*64/2/0.04/0.04/997.05,label='Laminar Flow');
plt.plot(t2,0.152*((1/(0.04*0.00089008*997.05))**0.25)*1.15*(t2**2.25)/0.04,label='Turbulence Flow');
plt.plot(t3,(t3**2)*1.15/12.96/0.04/np.log10(((0.00001/0.04/3.7)**1.11)+(6.9*0.00089008/0.04/t3/997.05)),label='Complete Turbulence');
#plt.plot(t,t**3,'r--',label='y=t^3');
#plt.plot(t, t, 'r--', t, t**2, 'bs', t, t**3, 'g^')
font1 = {'family' : 'Times New Roman',
'weight' : 'normal',
'size'   : 20,
}

plt.xlabel(u'u/(m/s)',font1)#fill the meaning of X axis
plt.ylabel(u'Hf',font1)#fill the meaning of Y axis
plt.title(u'Hf-u',font1)#add the title of the figure
plt.legend()

在這裏插入圖片描述

import numpy as np
import matplotlib.pyplot as plt
t1 = np.arange(0., 0.0893, 0.001)
t2 = np.arange(0.0893,0.2232,0.001)
t3 = np.arange(0.2233,0.4,0.001)
plt.plot(t1,t1*0.00089008*1.15*64/2/0.015/0.015/997.05,label='d=0.015m Laminar Flow');
plt.plot(t2,0.152*((1/(0.04*0.00089008*997.05))**0.25)*1.15*(t2**2.25)/0.015,label='d=0.015m Turbulence Flow');
plt.plot(t3,(t3**2)*1.15/12.96/0.015/np.log10(((0.00001/0.015/3.7)**1.11)+(6.9*0.00089008/0.015/t3/997.05)),label='d=0.015m Complete Turbulence');

plt.plot(t1,t1*0.00089008*1.15*64/2/0.04/0.04/997.05,label='d=0.04m Laminar Flow');
plt.plot(t2,0.152*((1/(0.04*0.00089008*997.05))**0.25)*1.15*(t2**2.25)/0.04,label='d=0.04m Turbulence Flow');
plt.plot(t3,(t3**2)*1.15/12.96/0.04/np.log10(((0.00001/0.04/3.7)**1.11)+(6.9*0.00089008/0.04/t3/997.05)),label='d=0.04m Complete Turbulence');

plt.plot(t1,t1*0.00089008*1.15*64/2/0.1/0.04/997.05,label='d=0.1m Laminar Flow');
plt.plot(t2,0.152*((1/(0.1*0.00089008*997.05))**0.25)*1.15*(t2**2.25)/0.1,label='d=0.1m Turbulence Flow');
plt.plot(t3,(t3**2)*1.15/12.96/0.1/np.log10(((0.00001/0.1/3.7)**1.11)+(6.9*0.00089008/0.1/t3/997.05)),label='d=0.1m Complete Turbulence');
#plt.plot(t,t**3,'r--',label='y=t^3');
#plt.plot(t, t, 'r--', t, t**2, 'bs', t, t**3, 'g^')
font1 = {'family' : 'DejaVu Sans',
'weight' : 'normal',
'size'   : 20,
}
plt.xlabel(u'u/(m/s)',font1)#fill the meaning of X axis
plt.ylabel(u'Hf',font1)#fill the meaning of Y axis
plt.title(u'Hf-u',font1)#add the title of the figure
plt.legend(loc='center left',bbox_to_anchor=(1, 0.5))

在這裏插入圖片描述

四、雷達圖

import numpy as np
import matplotlib.pyplot as plt
import matplotlib
matplotlib.rcParams['font.family'] = 'DejaVu Sans'
matplotlib.rcParams['font.sans-serif'] = ['DejaVu Sans']
lables = np.array([0,15,30,45,60,75,90,105,120,135,150,165,180,195,210,225,240,255,270,285,300,315,330,345])
nAttr = 24
date = np.array([31.24,24.99,18.74,14.17,12.5,14.17,18.74,24.99,31.24,35.81,37.49,35.81,31.24,24.99,18.74,14.17,12.5,14.17,18.74,24.99,31.24,35.81,37.49,35.81])
angles = np.linspace(0, 2*np.pi, nAttr, endpoint=False)
date = np.concatenate((date, [date[0]]))
angles = np.concatenate((angles, [angles[0]]))
fig = plt.figure(facecolor="white")
plt.subplot(111, polar=True)
plt.plot(angles, date, 'bo-', color = 'g', linewidth = 2)
plt.fill(angles, date, facecolor = 'g', alpha = 0.25)
plt.thetagrids(angles*180/np.pi, lables)
plt.figtext(0.52, 0.95, '', ha='center')
plt.grid(True)
#plt.savefig('dota_radar.JPG')
plt.show()

好了,今天這篇文章就到這裏啦,Java的學習一定要多寫多練。筆者會不定期做一些技術分享和工具使用心得,歡迎大家點贊和收藏!

在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章