如何定义四维柱状图4列数据?报错其中1列没有定义
问题描述:
我准备使用python写一个制作四维柱状图的代码,现在遇到了一些问题,请各位大侠高手指点,有偿!!
我有4列数据,前3列是属性,第4列是类别(+1,-1),我希望三个属性代表x,y,z,并且使用柱状图表示,柱状图的颜色代表类型(两种颜色)。
我的代码出错的部分如下:
read txt file
def Detectionplot():
data = pd.read_csv('D:\\ML\M316-svm-test.txt', sep = '\t', encoding = 'utf-8')
m = data['data']
fig = plt.figure()
ax = fig.subplot(111, projection='3d') # multiple maps using add_subplot
x = []
y = []
z = []
r = [] # 'r' is not defined r代表类别,为+1或-1
x = x.flatten('F')
y = y.flatten('F')
运行代码出错如下:
Python 3.7.0b4 (v3.7.0b4:eb96c37699, May 2 2018, 19:02:22) [MSC v.1913 64 bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.
================== RESTART: D:\ML\python3.7\4Dcolumnmap.py ==================
Traceback (most recent call last):
File "D:\ML\python3.7\4Dcolumnmap.py", line 32, in
for a in r:
NameError: name 'r' is not defined
请各位高手大侠出手相助,万分感谢!
答
ax = fig.subplot(111, projection='3d')
你这个就限定了3d映射,不能是4d
答
修改为'4d'吗?谢谢!