3

I have a surface density map in matplotlib for which I want the scale of the colorbar to be logarithmic.

Ideally using the LogNorm function should do the trick, but there are negative and null values, which gives an error when the values are turned logarithmic.
Is there function/method that I can use to include the areas with negative and null values in this respect?

sodd
  • 12,482
  • 3
  • 54
  • 62
firefly
  • 953
  • 2
  • 11
  • 18
  • 3
    What do you want to happen to the negative and null values? How do you want them to be incorporated into the log scaling? – BrenBarn May 22 '13 at 06:51
  • 1
    And you can use masked arrays to exclude the null and negative values. – gg349 May 22 '13 at 07:06
  • remember that `log(0) == -inf` and `log(-|x|) == nan` – tacaswell May 22 '13 at 13:57
  • 1
    @BrenBarn I don't want the values to be logged. Only the scale of the axis to be logarithmic, so the variation of the values can be seen much clearly. – firefly May 22 '13 at 23:19
  • @firefly: The values have to be logged at some point to create a logarithmic scale. If you just want to display their relative differences, you could try scalinng them all up by adding a constant to all of them to make the smallest one bigger than zero. – BrenBarn May 23 '13 at 01:15
  • The master branch of matplotlib on GitHub seems to include a new [`SymLogNorm`](http://matplotlib.org/dev/api/colors_api.html#matplotlib.colors.SymLogNorm). From what I understand from your question, this might suit your needs. – sodd May 26 '13 at 09:12

1 Answers1

3

Use symmetric logarithmic normalization or the SymLogNorm to plot data with both positive and negative values. Look at this documentation: Colormap Normalization.