Colorbar for imshow, centered at 0 and with a character scale

I want to generate a graph grid from several arrays with positive and negative values, with the log scale, using the same color plan.

I got the color sharing part (using ImageGrid values โ€‹โ€‹and common max and min values), and I know that I can get the logarithmic scale using LogNorm () in the imshow call in case of only positive values. But, given the presence of negative values, I will need a color panel in a symmetric logarithmic scale.

I found that it would be a solution at https://stackoverflow.com/a/3/9/12/12/12/12/12/ , but running the Yann code sample provides me with very different results, pure errors: Result of Yann example Looking at the code, I canโ€™t understand what is happening.

In addition to this, I found that on Matplotlib 1.2 the .SymmetricalLogScale.SymmetricalLogTransform scale requests a new argument not described in the documentation (linscale, which looks at the code of other transformations, I assume leaving it as 1 is a safe value).

Is the easiest solution to subclass LogNorm?

+4
source share
2 answers

I used a fairly simple recipe in the past to do just that, without having to do any subclasses. matplotlib.colors.SymLogNorm provides most of the functions you need, except that I have found it necessary to generate markings manually. Please note that this solution uses matplotlib 1.3.0, and I can use functions that were not available since 1.2.

def imshow_symlog(my_matrix, vmin, vmax, logthresh=5): img=imshow( my_matrix , vmin=float(vmin), vmax=float(vmax), norm=matplotlib.colors.SymLogNorm(10**-logthresh) ) maxlog=int(np.ceil( np.log10(vmax) )) minlog=int(np.ceil( np.log10(-vmin) )) #generate logarithmic ticks tick_locations=([-(10**x) for x in xrange(minlog,-logthresh-1,-1)] +[0.0] +[(10**x) for x in xrange(-logthresh,maxlog+1)] ) cb=colorbar(ticks=tick_locations) return img,cb 
+3
source

All Articles