Python表面的情节逐渐变化

2024-03-28 21:06:27 发布

您现在位置:Python中文网/ 问答频道 /正文

我需要为这个项目做一个数字。现在我得到了90%。不过,我希望我的身材有一些逐渐变化的颜色,一些红色和黑色的混合。python中是否有我可以实现它的地方?你知道吗

这是我得到的数字:The figure I got

这是我想要的数字:The figure with some gradually varied color 这是我的密码

import numpy as np
from matplotlib import cm, colors
import matplotlib.pyplot as plt
import scipy.special as sp
from mpl_toolkits.mplot3d import Axes3D


phi, theta = np.mgrid[0:2*np.pi:300j, 0:np.pi:150j]
Y30 = sp.sph_harm(0, 3, phi, theta).real
Y20 = sp.sph_harm(0, 2, phi, theta).real
R0 = 1
alpha30 = 0.1
alpha20 = 0.02
prefactor = alpha30*Y30 + alpha20 * Y20 +1
X = R0 * prefactor * np.sin(theta) * np.cos(phi)
Y = R0 * prefactor * np.sin(theta) * np.sin(phi)
Z = R0 * prefactor * np.cos(theta)

norm = colors.Normalize()
fig, ax = plt.subplots(subplot_kw=dict(projection='3d'), figsize=(10.5,10))
m = cm.ScalarMappable(cmap=cm.jet)

# hide the background axes
plt.axis('off')

# change the view
ax.view_init(1, )

ax.plot_surface(X, Y, Z, rstride=10, cstride=10, color = 'orangered', edgecolors='k',shade = True)
m.set_array(R0)

我不需要我的身材完全一样。我只想它有一些红色和黑色的混合,逐渐变化。我将非常感谢你的帮助。你知道吗


Tags: importasnpcmplt数字sinax