Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 467
Mari Avatar asked Feb 25 '19 09:02

Mari


1 Answers

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.

like image 82
Adam Bellaïche Avatar answered Nov 09 '22 21:11

Adam Bellaïche