Matplotlib绘制雷达图和三维图的示例代码
2020-06-25 08:08:18 来源:易采站长站 作者:易采站长站整理
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')













闽公网安备 35020302000061号