0

I need to make a figure for the project. Now I get 90% of it. However, I want my figure to have some gradually varied color, some mix of red and balck. Is there anyway in python where I can achieve it?

Here's the figure I got: The figure I got

Here's the figure I want: The figure with some gradually varied color Here's my code

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)

I don't need my figure to be exactly the same. I just want it to have some mixture of red and black, varying gradually. I would be very appreciate for the help.

Jack Z
  • 93
  • 1
  • 5
  • 1
    What you need is some sort of `LightSource` to have this shiny effect. Here are few links which you can refer: https://stackoverflow.com/questions/28232879/phong-shading-for-shiny-python-3d-surface-plots and http://physicalmodelingwithpython.blogspot.com/2015/08/illuminating-surface-plots.html I tried solving your problem today but couldn't make any progress. You might also probably have to create a custom color map as a mixture of black and orangered color. Here is a link out of several others on how to do that: https://matplotlib.org/examples/pylab_examples/custom_cmap.html – Sheldore Aug 29 '18 at 00:24
  • thank you so much! your comment is helpful – Jack Z Aug 29 '18 at 01:17

0 Answers0