Python 如何使三维散点图颜色栏调整到Z轴大小?

Python 如何使三维散点图颜色栏调整到Z轴大小?,python,python-3.x,pandas,matplotlib,scatter-plot,Python,Python 3.x,Pandas,Matplotlib,Scatter Plot,我试图将熊猫栏中的数据可视化为三维散点图。我面临的问题是将颜色栏匹配调整到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.sc

我试图将熊猫栏中的数据可视化为三维散点图。我面临的问题是将颜色栏匹配调整到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
但是你需要手动找到合适的值,可以是0.5,也可以是0.7


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

我不确定您想要什么。你想改变颜色吗?你所说的“用轴调整颜色图”是什么意思。我希望颜色条的高度与z轴的高度相同。@AdamBellaïchema您可以在这里找到答案: