3D Plot with Matplotlib: Hide axes but keep axis-labels?

3D Plot with Matplotlib: Hide axes but keep axis-labels?,第1张

3D Plot with Matplotlib: Hide axes but keep axis-labels?

I tried to run your pre, but it is not working in my computer.

Below you can see a solution for plotting a sphere. Basically, I turned the
color of the panes and spines to

alpha=0
by hand and make the ticks to be
empty lists (as you pointed out).

from mpl_toolkits.mplot3d import axes3dimport matplotlib.pyplot as pltfrom matplotlib import rcParamsimport numpy as nprcParams['axes.labelsize'] = 18rcParams['font.family'] = 'serif'rcParams['font.serif'] = ['Computer Modern Roman']rcParams['text.usetex'] = Truefig = plt.figure()ax = fig.add_subplot(111, projection='3d')u = np.linspace(0, 2 * np.pi, 100)v = np.linspace(0, np.pi, 100)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))ax.plot_surface(x, y, z,  rstride=4, cstride=4, color='b')# Get rid of the panesax.w_xaxis.set_pane_color((1.0, 1.0, 1.0, 0.0))ax.w_yaxis.set_pane_color((1.0, 1.0, 1.0, 0.0))ax.w_zaxis.set_pane_color((1.0, 1.0, 1.0, 0.0))# Get rid of the spinesax.w_xaxis.line.set_color((1.0, 1.0, 1.0, 0.0))ax.w_yaxis.line.set_color((1.0, 1.0, 1.0, 0.0))ax.w_zaxis.line.set_color((1.0, 1.0, 1.0, 0.0))# Get rid of the ticksax.set_xticks([]) ax.set_yticks([]) ax.set_zticks([])# Add the labelsax.set_xlabel('Third dimension' )ax.set_ylabel('Row(s)')ax.set_zlabel('Column(s)')plt.show()

And here is my output



欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5431460.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-11
下一篇 2022-12-11

发表评论

登录后才能评论

评论列表(0条)

保存