如何更改3D轴设置
我用matplotlib成功画出了这个图表。我想把B轴上的0.2、0.4、0.6这些数字去掉,并把A轴的间隔从200改成100。我已经尝试了很久,但还没找到办法……有没有什么建议呢?
这是我写的代码。
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
f_attributes=open("continuous.data","r")
x=[]
y=[]
spam=[]
count=1
skew=[]
fig = plt.figure()
ax = Axes3D(fig)
total=[]
while count<=1024:
attributes=f_attributes.readline()
attributes=attributes.replace(".\n","")
attributes=attributes.split(',')
classification=int(attributes[10].replace(".\n",""))
if float(attributes[8]) >=0:
skew.append(float(attributes[8]))
x.append(count)
y.append(classification)
if classification == 0:
ax.scatter(x, y, skew, c='g', marker='o')
else:
ax.scatter(x, y, skew, c='r', marker='o')
x=[]
y=[]
skew=[]
count+=1
ax.set_xlabel('A')
ax.set_ylabel('B')
ax.set_zlabel('C')
plt.show()
1 个回答
3
其实这并不简单,你需要深入了解这些对象。我一开始以为因为Axes3D是基于Axes的,所以可以使用set_yticklabels
这个方法,但显然这样不行。查看代码后,你会发现y轴是通过w_yaxis设置的,这个w_yaxis是axis3d.YAxis,最终又是基于axis.Axis的,而axis.Axis有set_ticklabels
这个方法,这样就可以用了:
ax.w_yaxis.set_ticklabels([])
你说的“把名为A的轴的间隔从200改成100”是什么意思呢?