簡體   English   中英

Matplotlib plot 3d 線在表面帶陰影

[英]Matplotlib plot 3d line on surface with shade

誰能幫我 plot 這樣的數字,3d 球體上的一些線條,以及這樣的坐標?

謝謝。
3d繪圖

以下是代碼

# 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)

以下是output圖在此處輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM