简体   繁体   中英

Matplotlib plot 3d line on surface with shade

Could anyone help me to plot such kind of figure, some lines on the 3d sphere, and such kind of coordinate?

Thanks.
3d绘图

The following is the code

# orintation
fig, axi = plt.subplots(figsize=figsize, dpi=dpi, subplot_kw={'projection': '3d'})
fig.patch.set_facecolor('white')
axorin = axi
ttheta = Table_theta[tidx][0]
tphi = Table_phi[tidx][0]
tpsi = Table_psi[tidx][0]
tnodes = get_ecoli_nodes_split_at(ttheta, tphi, tpsi, now_center=np.zeros(3), **problem_kwargs)
if trange_geo is None:
    tnode = np.vstack(tnodes)
    trange_geo = np.linalg.norm(tnode, axis=-1).max() * 0.8
# print('trange_geo=', trange_geo)
tmid = np.zeros(3)
axorin.set_xlim3d([tmid[0] - trange_geo, tmid[0] + trange_geo])
tticks = np.around(np.linspace(tmid[0] - trange_geo, tmid[0] + trange_geo, 21),
                   decimals=2)[1::6]
axorin.set_xticks(tticks)
axorin.set_xticklabels(tticks)
axorin.set_ylim3d([tmid[1] - trange_geo, tmid[1] + trange_geo])
tticks = np.around(np.linspace(tmid[1] - trange_geo, tmid[1] + trange_geo, 21),
                   decimals=2)[1::6]
axorin.set_yticks(tticks)
axorin.set_yticklabels(tticks)
axorin.set_zlim3d([tmid[2] - trange_geo, tmid[2] + trange_geo])
tticks = np.around(np.linspace(tmid[2] - trange_geo, tmid[2] + trange_geo, 21),
                   decimals=2)[1::6]
axorin.set_zticks(tticks)
axorin.set_zticklabels(tticks)
extFlow(axorin, trange_geo=trange_geo, **problem_kwargs)
# for tnodei in tnodes:
#     axorin.plot(tnodei[:, 0], tnodei[:, 1], tnodei[:, 2], 'dimgray')

# Jeffery sphere
u, v = np.mgrid[0:2*np.pi:100j, 0:np.pi:100j]
tr = np.linalg.norm(tnode, axis=-1).max()
x = np.cos(u) * np.sin(v) * tr
y = np.sin(u) * np.sin(v) * tr
z = np.cos(v) * tr
color1 = plt.get_cmap('gray')(np.linspace(0.2, 0.8, 256))
cmap = mcolors.LinearSegmentedColormap.from_list('my_colormap', color1)
axi.plot_surface(x, y, z, rstride=1, cstride=1, cmap=cmap, edgecolor='none', alpha=0.1)
# axi.plot(Table_P[tidx, 0] * tr, Table_P[tidx, 1] * tr, Table_P[tidx, 2] * tr, 'k', linewidth=3)
spf.colorline3d(Table_P[tidx] * tr, Table_t[tidx], show_project=show_project, ax0=axi, 
                tcl_lim=(tmin, tmax), tcl_fontsize=fontsize)
axi.scatter(Table_P[tidx, 0][0] * tr, Table_P[tidx, 1][0] * tr, Table_P[tidx, 2][0] * tr, 
            c='k', marker='s')
# clb = fig.axes[1]
# ticks = np.linspace(tmin, tmax, 5)
# clb.set_ticks(ticks)
# clb.ax.set_yticklabels(ticks, fontsize=30)
    
axi.set_xticklabels([])
axi.set_yticklabels([])
axi.set_zticklabels([])
axi.set_xlabel('$X_1$', fontsize=fontsize, labelpad=-5)
axi.set_ylabel('$X_2$', fontsize=fontsize, labelpad=-5)
axi.set_zlabel('$X_3$', fontsize=fontsize, labelpad=-5)

and the following is the output figure在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM