2

I have an array A which I have plotted in a contour plot using X and Y as coordinate axes,

plt.contourf(X,Y,A)

Contour plot of A

Problem is, the values in A vary from 1 to a very large number such that the color scale doesn't show a plot. When I plot log(A), I get the following contour,

Contour plot of log(A)

which is what I'm looking for. But I want to be able to view the values of the array A, instead of log(A), when I hover my cursor over a certain (X,Y) point. I already got an answer for how to do that, but how would I go about doing it while my colour scale remains log? Basically what I'm trying to do is to make the color scale follow a log pattern, but not the array values themselves.

Thanks a lot!

ThunderFlash
  • 412
  • 5
  • 20

2 Answers2

4

You can do this:

from matplotlib import colors
plt.contourf(X, Y, A, norm=colors.LogNorm())
plt.colorbar()
plt.show()

or

from matplotlib import ticker
plt.contourf(X, Y, A, locator=ticker.LogLocator())
plt.colorbar()
plt.show()
jotasi
  • 5,077
  • 2
  • 29
  • 51
Julien Spronck
  • 15,069
  • 4
  • 47
  • 55
1

A similar question was already asked for log-scaling the colors in a scatter plot: A logarithmic colorbar in matplotlib scatter plot

As is it was indicated there, there is an article in matplotlibs documentation that describes norms of colormaps: http://matplotlib.org/devdocs/users/colormapnorms.html

Essentially, you can set the norm of your contourplot by adding the keyword , norm=matplotlib.colors.LogNorm()

Community
  • 1
  • 1
jotasi
  • 5,077
  • 2
  • 29
  • 51