6

I have trying to visualize my data from pandas column as 3D scatter plot. I am facing the problem to adjust the color bar match to the exact size of my z axis.

My code :

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()

My Result

enter image description here

I want my color bar height to be adjusted with z axis height.

James Z
  • 12,209
  • 10
  • 24
  • 44
Mari
  • 698
  • 1
  • 8
  • 27

1 Answers1

4

One way to modify the size of your color bar is to use "shrink" axes property like this:

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

But you need to find the good value by hands.It could be 0.5 like 0.7.

However, you can try to calcul the needed value of shrink by getting the size of the z axis.

Niko Föhr
  • 28,336
  • 10
  • 93
  • 96
Adam Bellaïche
  • 427
  • 3
  • 16