0

So on the right I've got eigenvalue spectra of 1000 matrices scatter plotted over each other. On the left I wanted get a histogram oder density function to where eigenvalues occur and how often.

Two Panel Eigenvalue Distribution Plot

The histogram is done with numpy:

bins = 200
d = max(max(re), max(im), -min(re), -min(im))
histogram2D, binsX, binsY = np.histogram2d(re, im, bins=bins, range=((-d,d),(-d,d)))
histogram2D = histogram2D.T

Additionally to the amount of eigenvalues in each bin I wanted the histogram still to show clearly where eigenvalues occured and where they did not. So I made my own colormap:

def redblue_zeta(Zmin, Zmax, zeta=0.0):
   breakingpoint = float(Zmin)+float(zeta)/(float(Zmax)-float(Zmin))
   cdict = {'red':   ((0.0, 1.0, 1.0), (breakingpoint, 1.0, 0.0), (1.0, 1.0, 1.0)),
            'green': ((0.0, 1.0, 1.0), (breakingpoint, 1.0, 0.0), (1.0, 0.0, 0.0)),
            'blue':  ((0.0, 1.0, 1.0), (breakingpoint, 1.0, 1.0), (1.0, 0.0, 0.0))}
   return(cdict)

(This is a bit more complicated because I use the map for other plots where zeta>0 aswell.) And then I plotted:

Zmax = histogram2D.max()
cdict=cc.redblue_zeta(0,Zmax,zeta=0.0)
plt.register_cmap(name='rb', data=cdict)

plt.imshow(histogram2D, cmap=cm.get_cmap('rb'), extent=[-d, d, -d, d], interpolation='nearest')

So a point in the 2D plot is supposed to white if there are exactly zero eigenvalues in that bin. Otherwise it is supposed to be anything between blue and red. But that's not what I get. It seems that either the histogram or the colormap rounds small values to zero because I get a way too small blue region in the histogram plot. Any ideas? Thanks.

alice
  • 254
  • 2
  • 4
  • 9

1 Answers1

0

Is there a reason that you need your own color map, instead of a scaled version of one of the built ins? If not, then move to a builtin color map, and see if you can make it work that way. You can always tweak the colors later.

If you really do need your own, then I suspect the colormap isn't working quite right yet. Can you modify the register_cmap to first create the LinearSegmentedColor map, then register that map? http://matplotlib.org/api/colors_api.html#matplotlib.colors.LinearSegmentedColormap

Have you tried just displaying the map on its own to see how it looks?

Second, just to follow the docs, I'd switch the definition of your cdict from a a dictionary of tuples of tuples to a dictionary of lists of tuples.

Joan Smith
  • 931
  • 6
  • 15