前言
图就是门面,高大上的图看着就涨脸
1.调整颜色条位置
def weightShow(gause_masks,name="visWeight{}.png"):
plt.rcParams['font.sans-serif']=['SimHei'] #显示中文标签
plt.rcParams['axes.unicode_minus']=False #这两行需要手动设置
fig = plt.figure()
ax = Axes3D(fig)
w,h = gause_masks[0].shape[0],gause_masks[0].shape[1]
x = range(w)
y = range(h)
# 把x,y数据生成mesh网格状的数据,因为等高线的显示是在网格的基础上添加上高度值
X, Y = np.meshgrid(y, x)
for i,gause_mask in enumerate(gause_masks):
# ax = fig.add_subplot(1,2,i+1, projection='3d')
Z = gause_mask
ax.plot_surface(X, Y, Z, rstride = 1, # row 行步长
cstride = 1, # colum 列步长
cmap=plt.cm.jet ) # 渐变颜色
cf = ax.contourf(X, Y, Z,
zdir='Z', # 使用数据方向
offset=-2, # 填充投影轮廓位置
cmap=plt.cm.jet)
ax.set_zlim(-2, 2)
ax.set_xlabel("x轴")
ax.set_ylabel("y轴")
ax.set_zlabel("z轴")
if i ==1:
# https://blog.youkuaiyun.com/qq_42471423/article/details/116133697
# fig.add_axes([left, bottom, width, height])
cax = fig.add_axes([0.01,0.05,0.03,0.6]) # bar的举行描述(归一化后的尺度
cb = plt.colorbar(cf,cax=cax)
plt.savefig(name.format(i))
2.细化颜色、刻度
def weightShow(gause_masks,name="visWeight{}.png"):
plt.rcParams['font.sans-serif']=['SimHei'] #显示中文标签
plt.rcParams['axes.unicode_minus']=False #这两行需要手动设置
fig = plt.figure()
ax = Axes3D(fig)
w,h = gause_masks[0].shape[0],gause_masks[0].shape[1]
x = range(w)
y = range(h)
# 把x,y数据生成mesh网格状的数据,因为等高线的显示是在网格的基础上添加上高度值
X, Y = np.meshgrid(y, x)
for i,gause_mask in enumerate(gause_masks):
# ax = fig.add_subplot(1,2,i+1, projection='3d')
Z = gause_mask
ax.plot_surface(X, Y, Z, rstride = 1, # row 行步长
cstride = 1, # colum 列步长
cmap=plt.cm.jet ) # 渐变颜色
levels = np.arange(0,1.05,0.05) # 对颜色进行渐进细致设置
cf = ax.contourf(X, Y, Z,levels,
zdir='Z', # 使用数据方向
offset=-2, # 填充投影轮廓位置
cmap=plt.cm.jet)
ax.set_zlim(-2, 2)
ax.set_xlabel("x轴")
ax.set_ylabel("y轴")
ax.set_zlabel("z轴")
if i ==1:
# https://blog.youkuaiyun.com/qq_42471423/article/details/116133697
# fig.add_axes([left, bottom, width, height])
cax = fig.add_axes([0.01,0.22,0.03,0.5]) # bar的举行描述(归一化后的尺度
cb = plt.colorbar(cf,cax=cax)
#设置颜色条的刻度
cb.ax.yaxis.set_major_locator(MultipleLocator(0.1))
# cb.ax.yaxis.set_minor_locator(MultipleLocator(0.02))
plt.savefig(name.format(i))