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
I want my color bar height to be adjusted with z axis height.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With