1

If I'm generating a colorbar for an imshow plot, sometimes I end up with a result that includes only one tick-mark --- making the scale fairly indeterminate. Is there a way to ensure that at least 2 tick marks will be present? For example, making sure that at least both ends of the scale are labeled?

For example: enter image description here


Code to reproduce:

import numpy as np
import matplotlib as mpl
from matplotlib import pyplot as plt

SIZE = [100,100]
MIN  = 0.2

tt = np.square(np.random.uniform(size=SIZE))
for ii in range(SIZE[0]):
    for jj in range(SIZE[1]):
        while( tt[ii,jj] < MIN ): tt[ii,jj] = np.random.uniform()

ran = [ np.min(tt), np.max(tt) ]
print ran

use_norm = mpl.colors.LogNorm()
use_norm.vmin = ran[0]
use_norm.vmax = ran[1]

plt.imshow(tt, norm=use_norm)
plt.colorbar()
plt.show()

which produces something like:

enter image description here

DilithiumMatrix
  • 17,795
  • 22
  • 77
  • 119
  • 2
    Please include copy/pasteable code which demonstrates your problem. There is not much we can do to help with out that. – tacaswell Feb 18 '14 at 19:20
  • 1
    [This](http://stackoverflow.com/a/19243491/1860757) might help you – Francesco Montesano Feb 18 '14 at 21:09
  • Nice picture! What is a tick mark? How do you generate one? Do you mean that `10°` does not really help because you need more values on the right? – User Feb 18 '14 at 21:12

0 Answers0