9
mpl.rcParams['legend.fontsize'] = 10

fig1 = plt.figure()
ax = fig1.gca(projection='3d') 

ax.plot(tab_C[0], tab_C[1], zs=0, zdir='z', label = "Projection de la trajectoire de C", color='k')
ax.plot(tab_M[0], tab_M[1], zs=0, zdir='z', label = "Projection de la trajectoire de M", color='r')

for i in range(0,len(tab_t)):
    ax.plot(tab_C[0][i:i+2], tab_C[1][i:i+2], tab_C[2][i:i+2], color=plt.cm.rainbow(255*i/len(tab_t)))
    ax.plot(tab_M[0][i:i+2], tab_M[1][i:i+2], tab_M[2][i:i+2], color=plt.cm.rainbow(255*i/len(tab_t)))

ax.legend()

ax.set_xlabel('I')
ax.set_ylabel('J')
ax.set_zlabel('K')

m = cm.ScalarMappable(cmap=cm.rainbow)
m.set_array(tab_t)

plt.colorbar(m)

I've got this plot with my code

My plot

My problems are - I want to set label for the color bar but ScalarMappale don't have the methode set_label() - I want to set zmin=0 to see clearly the projection on the plan (0xy) but it seems that zmin here is 0.05 and when I do ax.set_zlim(bottom=0) It returns

Traceback (most recent call last):
  File "code.py", line 117, in <module>
    ax.set_zlim(bottom=0) 
  File "/usr/lib/pymodules/python2.7/mpl_toolkits/mplot3d/axes3d.py", line 515, in set_zlim3d
    lims = self._determine_lims(*args, **kwargs)
  File "/usr/lib/pymodules/python2.7/mpl_toolkits/mplot3d/axes3d.py", line 476, in _determine_lims
    xmin -= 0.05
TypeError: unsupported operand type(s) for -=: 'NoneType' and 'float'

Is there any way to solve my problems?

3

1 Answer 1

6

the correct way of calling is: set_zlim(min_value, max_value), if there are problems try also set_zlim3d

according to the documentation, colorbar object has a method set_label, see an example here

6
  • i've tried your suggest for set_zlim, it gave the same error. and for set_zlim3D it gave AttributeError: 'Axes3DSubplot' object has no attribute 'set_zlim3D'
    – pomxipum
    May 23, 2014 at 7:17
  • and when I use colorbar.ColorbarBase, it gave: AttributeError: 'QuadMesh' object has no attribute 'do_3d_projection'
    – pomxipum
    May 23, 2014 at 7:25
  • cb=plt.colorbar(m) cb.set_label('blabla') works totally fine for me
    – Sleepyhead
    May 23, 2014 at 17:25
  • ax.set_zlim(0,40) works as well. Maybe try adding from mpl_toolkits.mplot3d import Axes3D in the beginning
    – Sleepyhead
    May 23, 2014 at 17:27
  • 'set_ylim()' and 'set_xlim' work for me but 'set_zlim' always doesn't. I've imported Axes3D as well.
    – pomxipum
    May 26, 2014 at 15:20

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.