Jose,

Attached is an example that should at least point you in the right direction. I will also add it to the examples directory in the distribution.

Eric


Jose Gomez-Dans wrote:
Hi,
I am using Matplotlib to produce colormaps which I use with other
programs. I would like to produce a PNG file with the used colormap
(so that I can overlay). Rather than doing an imshow(<something>)
followed by colorbar, is there an easy way I could pass the colorbar
my cmap instance to have it plotted on its own? In essence, what I
want to do is to do a savefig, and get something along the lines of
what is shown here: <http://www.igidl.ul.pt/colorscale.gif>. I will
need to change the scale (i.e.,, the numbers :D) with each run.

So far, I have "cut+pasted" from a whole image, which is hardly convenient! :(

Cheers,
Jose
'''
Make a colorbar as a separate figure.
'''

import pylab
import matplotlib as mpl

# Make a figure and axes with dimensions as desired.
fig = pylab.figure(figsize=(8,1.5))
ax = fig.add_axes([0.05, 0.4, 0.9, 0.5])

# Set the colormap and norm to correspond to the data for which
# the colorbar will be used.
cmap = mpl.cm.cool
norm = mpl.colors.Normalize(vmin=5, vmax=10)

# ColorbarBase derives from ScalarMappable and puts a colorbar
# in a specified axes, so it has everything needed for a
# standalone colorbar.  There are many more kwargs, but the
# following gives a basic continuous colorbar with ticks
# and labels.
cb = mpl.colorbar.ColorbarBase(ax, cmap=cmap,
                                   norm=norm,
                                   orientation='horizontal')
cb.set_label('Some Units')

pylab.show()

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to