2

Is there a way to use SymLogNorm with imshow, but make the colorbar basically stretch the colors so that the colorbar actually appears linear?

Below is a short code

from pylab import *  
import numpy as np 
from matplotlib.colors import SymLogNorm
data = np.random.uniform(low=-10, high=10, size=(10,10))
norm = SymLogNorm(2,vmin=-10,vmax=10)
fig, axes = plt.subplots()
im = axes.imshow(data,extent=[-10,10,-10,10],cmap=plt.cm.jet,norm=norm)
cb = fig.colorbar(im) 

that produces this

sample imshow image

I basically want this image, but want to stretch the colorbar so the ticks appear linear, not log.

gboffi
  • 22,939
  • 8
  • 54
  • 85
ztech2020
  • 21
  • 1
  • The scale of 'colorbar' is logarithmic, which may be due to 'SymlogNorm'. If `norm= Nomalize(vmin=-10,vmax=10)`, then the range from -10 to 10 is displayed. – r-beginners May 17 '20 at 08:40
  • The problem is I want the image to map colors as Log scale, but want the colorbar to present it as linear scale. I suspect the only way to do this is by transforming the colormap itself, was just hoping for a shortcut. – ztech2020 May 18 '20 at 02:55
  • Does this answer your question? [Equidistant ticks on colorbar using SymLogNorm in matplotlib](https://stackoverflow.com/questions/33768117/equidistant-ticks-on-colorbar-using-symlognorm-in-matplotlib) – Holden Rohrer May 18 '20 at 15:30
  • That forces -2 to 2 in my case to be linear basically replicating what I have in SymLogNorm. The other problem is that this method simply moves the tick locations, it doesn't actually spread the colorbar to account for the log scale. So this works for your linear range in LogThresh, but you can't use it for the entire range or you'll make a fake linear colorbar that doesn't properly represent your data. – ztech2020 May 18 '20 at 20:22
  • Adding boundaries to my colormap call appears to have fixed this. Thanks for the suggestions! – ztech2020 May 18 '20 at 20:43

0 Answers0