如何使 3D 散点图颜色条调整到 Z 轴大小?

How to make 3D scatter plot color bar adjust to the Z axis size?

我试图将 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 轴高度调整。

修改颜色条大小的一种方法是使用“收缩”轴 属性,如下所示:

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

但你需要通过 hands.It 找到合适的值,可以是 0.5,比如 0.7。

不过,您可以尝试通过获取z轴的大小来计算所需的收缩值。