如何让3D散点图的颜色条根据Z轴大小进行调整?

6

我想将来自pandas列的数据可视化为3D散点图。 我遇到的问题是如何调整颜色条以匹配我的z轴的确切大小。

我的代码:

import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

s = pd.read_csv('FahrerVP8.out_1.csv', index_col=0)

ax = plt.figure()
three_d = ax.gca(projection='3d')
three_d1 = three_d.scatter(s['Latitude'], s['Longitude'],s['Mean_ VehicleSpeed'], c =s['Mean_ VehicleSpeed'] )
three_d.set_xlabel('Latitude')
three_d.set_ylabel('Longitude')
three_d.set_zlabel('Mean Vehicle Speed')


plt.colorbar(three_d1)
plt.show()

我的结果

在此输入图片描述

我希望我的颜色条高度能够随着z轴高度调整。


我不确定你想要什么。你想改变颜色吗?“颜色图与轴调整”是什么意思? - Adam Bellaïche
我想让颜色条的高度与Z轴高度相同。@AdamBellaïche - Mari
也许你可以在这里找到答案:https://dev59.com/NWMl5IYBdhLWcg3wsIyA - Adam Bellaïche
1个回答

4
使用“收缩”轴属性可以修改颜色条的大小,如下所示:

一种修改颜色条大小的方法是使用“收缩(shrink)”轴属性,例如:

plt.colorbar(three_d1, shrink=0.5) # an example

但你需要手动找到最佳值。它可能是0.5或0.7。

然而,您可以通过获取z轴的大小来尝试计算所需的shrink值。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接