title: Python, Spherical Plot- Color Scaling
body: <p>I'm pretty new with python. For the past two days I have been trying to figure out how to scale the color of a 3d plot (Antenna Radiation Pattern) with matplotlib. It looks like the scaling works in one of the xyz axis, but not when the scaling goes from the origin (radius). Any help is very appreciated.</p>
  <p>It's not my code, but i found it very useful.</p>
  <p>This is the code:</p>
  <ul>
  <li><p>The values ​​are read from an excel document</p>
  </li>
  <li><p>As you can see I'm trying to play around with this command <code>colors=plt.cm.jet((R)/(Rmax))</code>, but it's not working.</p>
  <pre><code>          import pandas as pd
            import numpy as np
            import matplotlib.pyplot as plt
            import mpl_toolkits.mplot3d.axes3d as axes3d
  
            # Read data file and plot
            df = pd.read_csv('EIRP_Data.csv') #henter data fra Excel
  
            theta1d = df['Theta']                  
            theta1d = np.array(theta1d);
            theta2d = theta1d.reshape([37,73]) #&quot;Theta&quot; kolonen blir hentet ut, satt i numpy array og gjort om til 2d array
  
            phi1d = df['Phi']
            phi1d = np.array(phi1d);
            phi2d = phi1d.reshape([37,73]) #&quot;Phi&quot; kolonen blir hentet ut, satt i numpy array og gjort om til 2d Array
  
            power1d = df['Power']
            power1d = np.array(power1d);
            power2d = power1d.reshape([37,73]) #&quot;Power&quot; kolonen blir hentet ut, satt i numpy array og gjort om til 2d array
  
            THETA = np.deg2rad(theta2d)
            PHI = np.deg2rad(phi2d)
            R = power2d
            Rmax = np.max(R)
            Rmin = np.min(R)
            N = R / Rmax
  
            #Gjør om polar til kartesisk
            X = R * np.sin(THETA) * np.cos(PHI) 
            Y = R * np.sin(THETA) * np.sin(PHI)
            Z = R * np.cos(THETA)
  
            fig = plt.figure()
  
            #plot spesifikasjoner/settings
            ax = fig.add_subplot(1,1,1, projection='3d') 
            ax.grid(True)
            ax.axis('on')
            ax.set_xlabel('X')
            ax.set_ylabel('Y')
            ax.set_zlabel('Z')
            ax.set_xticklabels([]) 
            ax.set_yticklabels([])
            ax.set_zticklabels([])
  
            #colors =plt.cm.jet( (X.max()-X)/float((X-X.min()).max()))
            colors =plt.cm.jet( (R)/(Rmax) )
            ax.plot_surface(
                X, Y, Z, rstride=1, cstride=1, facecolors=colors,
                linewidth=0, antialiased=True, alpha=0.5, zorder = 0.5)
  
            ax.view_init(azim=300, elev = 30)
  
            # Add Spherical Grid
            phi ,theta = np.linspace(0, 2 * np.pi, 40), np.linspace(0, np.pi, 40)
            PHI, THETA  = np.meshgrid(phi,theta)
            R = Rmax
            X = R * np.sin(THETA) * np.cos(PHI)
            Y = R * np.sin(THETA) * np.sin(PHI)
            Z = R * np.cos(THETA)
  
            ax.plot_wireframe(X, Y, Z, linewidth=0.5, rstride=20, cstride=20)
  
            plt.show()
  </code></pre>
  </li>
  </ul>
  <p><a href="https://i.stack.imgur.com/beVD8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/beVD8.png" alt="urrent plot" /></a></p>