Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change color and add grid lines on python surface plot?

I am new here, please be gentle. I am doing a project which requires me to draw the figure of octupole. I used python surface plot and got a result like this:

the figure I got

However, my professor wants something like this:

the figure I want

Please ignore the 226Ra in the figure. I want to change the color of my plot to red, and add the grid lines like that. Is there any way I can do it? I would be very appreciated. Here's my code:

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




l = 3    # degree
m = 0    # order
PHI, THETA = np.mgrid[0:2*np.pi:300j, 0:np.pi:150j]
R = sp.sph_harm(m, l, PHI, THETA).real

s = 1
X = (s*R*0.28+1) * np.sin(THETA) * np.cos(PHI)
Y = (s*R*0.28+1) * np.sin(THETA) * np.sin(PHI)
Z = (s*R*0.29+1) * np.cos(THETA)

norm = colors.Normalize()
fig, ax = plt.subplots(subplot_kw=dict(projection='3d'), figsize=(14,10))
m = cm.ScalarMappable(cmap=cm.jet)
ax.plot_surface(X, Y, Z, rstride=1, cstride=1, facecolors=cm.jet(norm(R)))
m.set_array(R)
fig.colorbar(m, shrink=0.8);
like image 325
Jack Z Avatar asked Aug 24 '18 17:08

Jack Z


1 Answers

Just replace your plot_surface line with the following and comment out fig.colorbar(m, shrink=0.8);. You can use any other color as per your wish from this page.

ax.plot_surface(X, Y, Z, rstride=10, cstride=10, color='orangered', edgecolors='k', lw=0.6) 

Output

enter image description here

like image 156
Sheldore Avatar answered Sep 21 '22 16:09

Sheldore