如何删除Axes3D类中的轴? [英] How can I remove the axes in an Axes3D class?
本文介绍了如何删除Axes3D类中的轴?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在这样使用mplot3d:
I am using mplot3d like this:
fig = plt.figure(figsize=(14,10))
ax = Axes3D(fig,azim=azimuth,elev=elevation)
ax.grid(on=False)
# Additional axes
xspan = np.linspace(0,80+20)
yspan = np.linspace(0,60+20)
zspan = np.linspace(0,60+20)
ax.plot3D(xspan,np.zeros(xspan.shape[0]),np.zeros(xspan.shape[0]),'k--')
ax.plot3D(np.zeros(yspan.shape[0]),yspan,np.zeros(yspan.shape[0]),'k--')
ax.plot3D(np.zeros(zspan.shape[0]),np.zeros(zspan.shape[0]),zspan,'k--')
ax.text(xspan[-1]+10, .5, .5, "x", color='red')
ax.text(.5, yspan[-1]+10, .5, "y", color='red')
ax.text(.5, .5, zspan[-1]+10, "z", color='red')
NZindices = np.nonzero(t2)[0]
#print "Nonzero values of T^2", len(NZindices), "out of", X.shape[0]
ONZ_X, ONZ_Y, ONZ_Z, ONZ_p = [],[],[],[]
INZ_X, INZ_Y, INZ_Z, INZ_p = [],[],[],[]
# Separate indices I/O
for ind in NZindices:
if ind <= HALF_INDICES:
INZ_X.append( X[ind] )
INZ_Y.append( Y[ind] )
INZ_Z.append( Z[ind] )
INZ_p.append( t2[ind] )
else:
ONZ_X.append( X[ind] )
ONZ_Y.append( Y[ind] )
ONZ_Z.append( Z[ind] )
ONZ_p.append( t2[ind] )
cax = ax.scatter(ONZ_X, ONZ_Y, ONZ_Z, c=ONZ_p, marker='o', s=20 )
cax = ax.scatter(INZ_X, INZ_Y, INZ_Z, c=INZ_p, marker='<', s=20 )
fig.colorbar( cax, shrink=0.7 )
success = float(len(NZindices))/X.shape[0]*100
fig.savefig(fname)
#plt.show()
plt.clf()
plt.close()
我想删除 Axes3D 中默认出现的原始 (x,y,z) 轴.有任何想法吗?谢谢!
I want to remove the original (x,y,z) axes that come by default in Axes3D. Any ideas? Thanks!
推荐答案
如果我正确理解你的问题,你需要做的就是调用 ax.axis("off")
或等效的,<代码>ax.set_axis_off().
If I understand your question correctly, all you need to do is call ax.axis("off")
or equivalently, ax.set_axis_off()
.
只是为了确保我们在同一页面上,您的示例代码可能会产生这样的内容(如果它可以在您发布时执行...):
Just to make sure we're on the same page, your example code might produce something like this (if it could be executed as you posted it...):
虽然你想要这样的东西:
While you want something like this:
以下是生成以下示例的代码,以供将来参考:
Here's the code to generate the example below, for future reference:
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
fig = plt.figure()
ax = Axes3D(fig)
# Draw x, y, and z axis markers in the same way you were in
# the code snippet in your question...
xspan, yspan, zspan = 3 * [np.linspace(0,60,20)]
zero = np.zeros_like(xspan)
ax.plot3D(xspan, zero, zero,'k--')
ax.plot3D(zero, yspan, zero,'k--')
ax.plot3D(zero, zero, zspan,'k--')
ax.text(xspan.max() + 10, .5, .5, "x", color='red')
ax.text(.5, yspan.max() + 10, .5, "y", color='red')
ax.text(.5, .5, zspan.max() + 10, "z", color='red')
# Generate and plot some random data...
ndata = 10
x = np.random.uniform(xspan.min(), xspan.max(), ndata)
y = np.random.uniform(yspan.min(), yspan.max(), ndata)
z = np.random.uniform(zspan.min(), zspan.max(), ndata)
c = np.random.random(ndata)
ax.scatter(x, y, z, c=c, marker='o', s=20)
# This line is the only difference between the two plots above!
ax.axis("off")
plt.show()
这篇关于如何删除Axes3D类中的轴?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文