python - 如何在图表中添加色标?

标签 python matplotlib 3d

在下面的代码中,我想让我的图表变得丰富多彩,并为其添加色标,如下面的示例 1 所示。我该怎么做呢?换句话说,我想获取 3D 图形并添加颜色和比例,如示例 1 中所示。

Example 1

What my current graph looks like

这是我的代码:

import matplotlib as plt
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
import matplotlib.pyplot as plt
from test4 import model_brdf2
#from test4 import theta_i_uniq
#from test4 import theta_r_uniq
#from test4 import phi_r_uniq

def polar2cart(rho,theta,phi):
    x = rho* np.sin(theta)*np.cos(phi)
    y = rho *np.sin(theta)*np.sin(phi)
    z = rho *np.cos(theta)
    return(x,y,z)


theta_r_uniq = np.deg2rad(np.linspace(-80,80))
phi_r_uniq = np.deg2rad(np.linspace(-180, 180))
Theta_grid, Phi_grid = np.meshgrid(theta_r_uniq, phi_r_uniq)
nrows, ncols = Theta_grid.shape
#Theta_grid = Theta_grid.flatten()
#Phi_grid = Phi_grid.flatten()



fig = plt.figure()
ax = plt.axes(projection="3d")
theta_i_rad = np.deg2rad(-60.0)
r_brdf = model_brdf2(theta_i_rad,0,Theta_grid,Phi_grid)
Xgrid, Ygrid, Zgrid = polar2cart(r_brdf,Theta_grid, Phi_grid)


#z = np.cos(Theta_grid) #+ np.sin(Phi_grid)

#ax.plot3D(Xgrid, Ygrid, z, )
ax.plot_wireframe(Xgrid, Ygrid, Zgrid)

plt.show()

最佳答案

您需要将图本身着色为 supplying a color map to plot_wireframe 。然后add the color bar .

关于python - 如何在图表中添加色标?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58564147/

相关文章:

python : How to write list to csv with N items per row

python - 在 python 中评估迭代器

python - 科学刻度标签符号调整

java - 3D java数组打印,另一种方式

c++ - 网格操作/变形库

Python-读取文本文件的每一行并将每一行传递给变量

python - 向字符串添加简单值

python - 使用勒让德多项式在极坐标中构建并绘制 Matplotlib 二维直方图

Python隐藏刻度但显示刻度标签

algorithm - 寻找体素化策略的一些指示