今天就跟大家聊聊有关使用Matplotlib怎么绘制一个雷达图,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。
1.雷达图
程序示例
'''1.空白极坐标图''' import matplotlib.pyplot as plt plt.polar() plt.show() '''2.绘制一个极坐标点''' import numpy as np import matplotlib.pyplot as plt # 极坐标(0.25*pi,20) plt.polar(0.25*np.pi, 20, 'ro', lw=2) # 'ro'红色圆点 plt.ylim(0,50) plt.show() '''3.绘制多个极坐标点''' 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'红色圆点 plt.ylim(0,100) plt.show() '''4.链接极坐标点''' 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.闭合链接极坐标点''' 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,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 # 只需在末尾添加一个和起始点重合的点 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.绘制成绩雷达图''' 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) # 均分极坐标 scores.append(scores[0]) # 在末尾添加第一个值,保证曲线闭合 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.绘制三维曲线,并设置图例字号''' 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') # 设置图像属性 # 测试数据 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 测试曲线') # 设置图例的字体,字号 font = fm.FontProperties('simhei') mpl.rcParams['legend.fontsize'] = 10 ax.legend(prop=font) plt.show() '''2.绘制三维柱状图,并每个柱子颜色随机''' 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()
看完上述内容,你们对使用Matplotlib怎么绘制一个雷达图有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注亿速云行业资讯频道,感谢大家的支持。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。