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

Mar*_*ari 6 python matplotlib scatter-plot python-3.x pandas

我试图将 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()
Run Code Online (Sandbox Code Playgroud)

我的结果

在此处输入图片说明

我希望用 z 轴高度调整我的彩条高度。

Ada*_*che 4

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

plt.colorbar(three_d1, shrink=0.5) # an example
Run Code Online (Sandbox Code Playgroud)

但是你需要用手找到合适的值。它可能是0.5,比如0.7。

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