Plotting the temperature distribution on a sphere with python

前端 未结 2 885
闹比i
闹比i 2020-12-21 06:01

I have the following problem:

a have N points on a sphere specified by a array x, with x.shape=(N,3). This array contains their cartesian coordinates. Furthermore, a

2条回答
  •  清歌不尽
    2020-12-21 06:45

    One way to do this is to set facecolors by mapping your heat data through the colormap.

    Here's an example:

    enter image description here

    from mpl_toolkits.mplot3d import Axes3D
    import matplotlib.pyplot as plt
    import numpy as np
    from matplotlib import cm
    
    fig = plt.figure()
    ax = fig.add_subplot(111, projection='3d')
    
    u = np.linspace(0, 2 * np.pi, 80)
    v = np.linspace(0, np.pi, 80)
    
    # create the sphere surface
    x=10 * np.outer(np.cos(u), np.sin(v))
    y=10 * np.outer(np.sin(u), np.sin(v))
    z=10 * np.outer(np.ones(np.size(u)), np.cos(v))
    
    # simulate heat pattern (striped)
    myheatmap = np.abs(np.sin(y))
    
    ax.plot_surface(x, y, z, cstride=1, rstride=1, facecolors=cm.hot(myheatmap))
    
    plt.show()
    

    Here, my "heatmap" is just stripes along the y-axis, which I made using the function np.abs(np.sin(y)), but anything that goes form 0 to 1 will work (and, of course, it needs to match the shapes on x, etc.

提交回复
热议问题