我正在寻找3个变量,并通过给点上色显示第4个变量。我找到图片,但没有数据集的例子。
我正在使用来自的数据集 https://www.kaggle.com/uciml/forest-cover-type-dataset
我没有成功尝试以下代码。
wild_areas=cover.groupby(['Wilderness_Area'], axis=0)#.count()
from pandas import DataFrame
wild_area_dict={}
wild_area_cover_dict = {}
wild_area_cover_wocount_dict = {}
wild_area_tree_names = {}
for area in wild_areas:
cover_groups=area[1].groupby(['Cover_Type'])
wild_area_cover_dict[area[0]]=\
cover_groups['Cover_Type'].count()
cover_dfs=[]
for cover_group in cover_groups:
cover_dfs.append(cover_group[1])
wild_area_cover_wocount_dict[area[0]]=cover_dfs
wild_area_dict[area[0]]=area[1]
area_trees=wild_area_cover_dict[area[0]]
print(wild_dict[area[0]])
print(area_trees) #cover_type # and sum of cover_type
tree_ids=list(area_trees.index) # [1,2,5,7]
tree_names=[]
for tree in tree_ids:
tree_names.append(trees_dict[tree])
wild_area_tree_names[area[0]]=tree_names
freq=list(area_trees)
wild_area4 = wild_area_dict[4].reset_index()
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
x=wild_area4[['Aspect']]
t=wild_area4[['Elevation']]
z=wild_area4[['Horizontal_Distance_To_Hydrology']]
v=wild_area4[['Cover_Type']] # I want this to be the dots
cmhot = plt.get_cmap("hot")
ax.scatter(x,y,z, v, c=np.abs(v),s=50, cmap=cmhot)
ax.set_xlabel('Aspect')
ax.set_ylabel('Elevation')
ax.set_zlabel('Horizontal Distance to Hydrology')
ax.legend(fontsize='small')
plt.show()