【发布时间】:2019-07-25 06:11:30
【问题描述】:
我有 160 个国家的数据集,以及每个国家在 12 年内的人口密度。我想将其绘制为 3D 散点图,但出现此错误:
- ValueError:要解压的值太多(预计 3 个)
我创建了三个列表 - “年份”、“国家名称”、“人口密度” 但似乎我做错了。 这是数据集的一个样本:
这是我的代码:
g1 = population_density["year"]
g2 = population_density["country_name"]
g3 = population_density["population_density_(people per sq. km of land area)"]
data = (g1, g2, g3)
colors= list(np.random.choice(range(256), size=160))
groups = ("year", "population density per sq.km", "countries")
# Create plot
fig = plt.figure(figsize = (10,8))
#ax = Axes3D(fig)
ax = fig.add_subplot(111, projection='3d')
#ax = fig.gca(projection='3d')
for data, color, group in zip(data, colors, groups):
x, y, z = data
ax.scatter(x, y, z, alpha=0.8, c=color, edgecolors='none', s=30, label=group)
plt.title('Population Density Over The Years')
plt.legend(loc=2)
plt.show()
最后,我想要这个 3d 图的所有年份的散点图。请帮忙!
【问题讨论】:
标签: python plot dataset mplot3d scatter3d