Betere Dingen

| 30-06-2010 16:02Pylab logarithmic colorbars

The one alternative I know is to create a logarithmic colormap for each dataset. I like this solution better.

#!/usr/env/python

from pylab import *
from numpy import *

samples = 20

data = rand(samples,samples)

ticklabellocs = arange(0.0,1.2,0.2)
ticklabels = []
for tli in ticklabellocs:
  label = u'%0.3f'%tli
  ticklabels.append(label)

ticklabels[0] = '0'

figure(num=1)
X, Y = meshgrid(range(samples),range(samples))
myContour = contourf(X,Y,data**0.5,arange(0.0,1.01,0.01),cmap=cm.hot)

cla()
set_cmap('hot')
imshow(data)

Clines = contour(X, Y, data, ticklabellocs, colors = '#000000', hold='on')

myCbar = colorbar(myContour, ticks=list(ticklabellocs**0.5))
myCbar.ax.set_yticklabels(ticklabels)

xlim((0,samples-1))
ylim((0,samples-1))

show()

One or more comments are waiting for approval by an editor.

(optional field)
(optional field)

Comment moderation is enabled on this site. This means that your comment will not be visible until it has been approved by an editor.

Remember personal info?
Small print: All html tags except <b> and <i> will be removed from your comment. You can make links by just typing the url or mail-address.