3

I would like to enforce that the ticks of my colorbar are equally spaced on the colorbar (not in their values) using SymLogNorm(), like they are for example in the default mode of LogNorm(). How could I do this without doing it by hand, i.e. without doing like the following:

plt.colorbar(ticks=[vmin, value1, ... , vmax])

What I want is basically to have the same ticks as I would have using LogNorm() (Magnitudes). Here is how my code basically works:

import ...
...
y    = np.loadtxt('my_data.dat')
vmin_a = y[0]
vmax_a = y[1]

norm_a = SymLogNorm(linthresh=0.5, linscale=0.03, vmin=vmin_a, vmax=vmax_a)

plt.figure(1)
plt.scatter(x[0], x[1], marker='.', s=7, linewidths=0, c=x[3], cmap= \
          plt.get_cmap('RdBu_r'), norm=norm_rs)
plt.xlabel(xax)    
plt.ylabel(yax)    
plt.colorbar()

pl.xlim([vmin_a, vmax_a])
pl.ylim([vmin_a, vmax_a])

plt.show()

I think the following picture explains very well how I do not want it, i.e. how it actually looks like: enter image description here I am thankful for any hint. Regards

DonkeyKong
  • 465
  • 1
  • 5
  • 16

1 Answers1

1

As far as I can see, one has to set ticks by hand using SymLogNorm. I solved my problem by defining:

tick_locations_plot=( [vmin]
                  + [-(10.0**x) for x in range(minlog-1,-logthresh-1,-1)]
                  + [0.0]
                  + [(10.0**x) for x in range(-logthresh,maxlog-1)]
                  + [vmax] )

where

maxlog=int(np.ceil( np.log10(vmax) ))
minlog=int(np.ceil( np.log10(-vmin) ))

Then using

plt.colorbar(ticks=tick_locations)

does what I was looking for.

DonkeyKong
  • 465
  • 1
  • 5
  • 16
  • What is `logthresh`? – gauteh Mar 22 '17 at 09:28
  • 1
    @gauteh it's a threshold in to determine where the plot is log verse linear. [See this post](https://stackoverflow.com/questions/3305865/what-is-the-difference-between-log-and-symlog) – Novice C Jul 20 '17 at 08:03