【问题标题】:How to make 3D scatter plot color bar adjust to the Z axis size?如何使 3D 散点图彩条调整为 Z 轴大小?
【发布时间】:2019-07-18 16:49:39
【问题描述】:

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

【问题讨论】:

  • 我不确定你想要什么。你想改变颜色吗? “用轴调整颜色图”是什么意思?
  • 1.我希望彩条高度与 z 轴高度相同。@AdamBellaïche
  • 也许你会在这里找到答案:stackoverflow.com/questions/18195758/…

标签: python python-3.x pandas matplotlib scatter-plot


【解决方案1】:

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

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

但你需要手动找到好的价值。它可能是 0.5 和 0.7。

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

【讨论】:

    猜你喜欢
    • 2016-08-21
    • 2020-01-31
    • 1970-01-01
    • 2016-03-07
    • 2018-10-27
    • 2015-02-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多