您好,登錄后才能下訂單哦!
今天就跟大家聊聊有關(guān)使用Matplotlib怎么繪制一個(gè)雷達(dá)圖,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結(jié)了以下內(nèi)容,希望大家根據(jù)這篇文章可以有所收獲。
1.雷達(dá)圖
程序示例
'''1.空白極坐標(biāo)圖''' import matplotlib.pyplot as plt plt.polar() plt.show() '''2.繪制一個(gè)極坐標(biāo)點(diǎn)''' import numpy as np import matplotlib.pyplot as plt # 極坐標(biāo)(0.25*pi,20) plt.polar(0.25*np.pi, 20, 'ro', lw=2) # 'ro'紅色圓點(diǎn) plt.ylim(0,50) plt.show() '''3.繪制多個(gè)極坐標(biāo)點(diǎn)''' import numpy as np import matplotlib.pyplot as plt theta = np.array([0.25,0.5,0.75,1,1.25,1.5,1.75,2]) r = [75,60,50,70,50,85,45,70] plt.polar(theta*np.pi, r, 'ro', lw=2) # 'ro'紅色圓點(diǎn) plt.ylim(0,100) plt.show() '''4.鏈接極坐標(biāo)點(diǎn)''' import numpy as np import matplotlib.pyplot as plt theta = np.array([0.25,0.5,0.75,1,1.25,1.5,1.75,2]) r = [75,60,50,70,50,85,45,70] plt.polar(theta*np.pi, r, 'ro-', lw=2) plt.ylim(0,100) plt.show() '''5.閉合鏈接極坐標(biāo)點(diǎn)''' import numpy as np import matplotlib.pyplot as plt # 只需在末尾添加一個(gè)和起始點(diǎn)重合的點(diǎn) theta = np.array([0.25,0.5,0.75,1,1.25,1.5,1.75,2,0.25]) r = [75,60,50,70,50,85,45,70, 75] plt.polar(theta*np.pi, r, 'ro-', lw=2) plt.ylim(0,100) plt.show() '''6.填充顏色''' import numpy as np import matplotlib.pyplot as plt # 只需在末尾添加一個(gè)和起始點(diǎn)重合的點(diǎn) theta = np.array([0.25,0.5,0.75,1,1.25,1.5,1.75,2,0.25]) r = [75,60,50,70,50,85,45,70, 75] plt.polar(theta*np.pi, r, 'ro-', lw=2) plt.fill(theta*np.pi, r, facecolor='r', alpha=0.5) # 填充 plt.ylim(0,100) plt.show() '''7.繪制成績(jī)雷達(dá)圖''' import numpy as np import matplotlib.pyplot as plt courses = ['C++', 'Python', 'Java', 'C', 'C#', 'Go', 'Matlab'] scores = [82,100,90,78,40,66,88] datalength = len(scores) angles = np.linspace(0, 2*np.pi, datalength, endpoint=False) # 均分極坐標(biāo) scores.append(scores[0]) # 在末尾添加第一個(gè)值,保證曲線閉合 angles = np.append(angles, angles[0]) plt.polar(angles, scores, 'rv-', lw=2) plt.thetagrids(angles*180/np.pi, courses, fontproperties='simhei') plt.fill(angles, scores, facecolor='r', alpha=0.4)
2.三維圖
程序示例
'''1.繪制三維曲線,并設(shè)置圖例字號(hào)''' import matplotlib.pyplot as plt import numpy as np import matplotlib as mpl import matplotlib.font_manager as fm from mpl_toolkits.mplot3d import Axes3D # 不可缺少 fig = plt.figure() ax = fig.gca(projection='3d') # 設(shè)置圖像屬性 # 測(cè)試數(shù)據(jù) theta = np.linspace(-4 * np.pi, 4*np.pi, 100) z = np.linspace(-4,4,100) * 0.3 r = z**4 + 1 x = r*np.sin(theta) y = r*np.cos(theta) ax.plot(x,y,z,'b^-', label='3D 測(cè)試曲線') # 設(shè)置圖例的字體,字號(hào) font = fm.FontProperties('simhei') mpl.rcParams['legend.fontsize'] = 10 ax.legend(prop=font) plt.show() '''2.繪制三維柱狀圖,并每個(gè)柱子顏色隨機(jī)''' import numpy as np import matplotlib.pyplot as plt import mpl_toolkits.mplot3d x = np.random.randint(0,40,10) y = np.random.randint(0,40,10) z = 80*abs(np.sin(x+y)) ax = plt.subplot(projection='3d') for xx, yy, zz in zip(x,y,z): color = np.random.random(3) ax.bar3d(xx, yy, 0, dx=1, dy=1, dz=zz, color=color) ax.set_xlabel('X軸', fontproperties='simhei') ax.set_ylabel('Y軸', fontproperties='simhei') ax.set_zlabel('Z軸', fontproperties='simhei') plt.show()
看完上述內(nèi)容,你們對(duì)使用Matplotlib怎么繪制一個(gè)雷達(dá)圖有進(jìn)一步的了解嗎?如果還想了解更多知識(shí)或者相關(guān)內(nèi)容,請(qǐng)關(guān)注億速云行業(yè)資訊頻道,感謝大家的支持。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。