python - matplotlib: any way to get existing colorbars? -


in matplotlib's object oriented style can current axes, lines , images in existing figure:

fig.axes fig.axes[0].lines fig.axes[0].images 

but haven't found way existing colorbars, have assign colorbar name when first creating it:

cbar = fig.colorbar(image) 

is there way colorbar objects in given figure if didn't assign them names?

the problem colorbar added "just another" axis, listed 'normal' axes.

import matplotlib.pyplot plt import numpy np  data = np.random.rand(6,6) fig = plt.figure(1) fig.clf() ax = fig.add_subplot(1,1,1) cax = ax.imshow(data, interpolation='nearest', vmin=0.5, vmax=0.99) print "before adding colorbar:" print fig.axes fig.colorbar(cax) print "after adding colorbar:" print fig.axes 

for me, gives result:

before adding colorbar: [<matplotlib.axes._subplots.axessubplot object @ 0x00000000080d1d68>] after adding colorbar: [<matplotlib.axes._subplots.axessubplot object @ 0x00000000080d1d68>, <matplotl ib.axes._subplots.axessubplot object @ 0x0000000008268390>] 

that is, there 2 axes in figure, second 1 new colorbar.

edit: code based on answer given here: https://stackoverflow.com/a/2644255/2073632


Comments

Popular posts from this blog

javascript - How to synchronize the Three.js and HTML/SVG coordinate systems (especially w.r.t. the y-axis)? -

javascript - How do I find how many occurences are there of a highlighted string, and which occurence is it? -

java - Reading data from multiple zip files and combining them to one -