Problem with matplotlib.colors.LogNorm

So I been using the log scale provided by matplotlib.colors.LogNorm, but have been seing bizarre behaviour. Basically, high values are not displayed properly. I give simple examples below with just two possible values in the matrix, but all the same issues arise with more varied values.

First notice that the high value (100000) is displayed as being of value=1:

from pylab import *
from matplotlib.colors import LogNorm

matrix = ones((30,30))
matrix = matrix*440
matrix[29,29] = 100000

matshow(matrix, norm=LogNorm(vmin=1, vmax=1000000))
colorbar()
show()

The cutoff value for incorrect display (for the scale I am using) seems to be at 32000:

from pylab import *
from matplotlib.colors import LogNorm

matrix = ones((30,30))
matrix = matrix*440
matrix[29,29] = 32000

matshow(matrix, norm=LogNorm(vmin=1, vmax=1000000))
colorbar()
show()

However, if the value is really high, the color displayed changes again, although still not to the correct color (please try with values 918000, 920000, and 999000 to see see it progress):

from pylab import *
from matplotlib.colors import LogNorm

matrix = ones((30,30))
matrix = matrix*440
matrix[29,29] = 918000

matshow(matrix, norm=LogNorm(vmin=1, vmax=1000000))
colorbar()
show()

And if one specifies no limits to LogNorm, the colorbar displayed is incomplete and the colour displayed is wrong in a different way then when specifying the limits (try value = 999000 as well).

from pylab import *
from matplotlib.colors import LogNorm

matrix = ones((30,30))
matrix = matrix*440
matrix[29,29] = 918000

matshow(matrix, norm=LogNorm())
colorbar()
show()

Either I am completely missing something or there is a major bug.

I am using mpl checked out from svn on 26 March.

Thanks,
Suresh

I see where the problem (or at least one problem) is, and I will try to get it fixed by tomorrow. In the meantime, I think you will get the results you want by simply converting your arrays to floating point:

matshow(matrix.astype(float), ...)

Eric

Suresh Pillai wrote:

···

So I been using the log scale provided by matplotlib.colors.LogNorm, but have been seing bizarre behaviour. Basically, high values are not displayed properly. I give simple examples below with just two possible values in the matrix, but all the same issues arise with more varied values.

First notice that the high value (100000) is displayed as being of value=1:

from pylab import *
from matplotlib.colors import LogNorm

matrix = ones((30,30))
matrix = matrix*440
matrix[29,29] = 100000

matshow(matrix, norm=LogNorm(vmin=1, vmax=1000000))
colorbar()
show()

The cutoff value for incorrect display (for the scale I am using) seems to be at 32000:

from pylab import *
from matplotlib.colors import LogNorm

matrix = ones((30,30))
matrix = matrix*440
matrix[29,29] = 32000

matshow(matrix, norm=LogNorm(vmin=1, vmax=1000000))
colorbar()
show()

However, if the value is really high, the color displayed changes again, although still not to the correct color (please try with values 918000, 920000, and 999000 to see see it progress):

from pylab import *
from matplotlib.colors import LogNorm

matrix = ones((30,30))
matrix = matrix*440
matrix[29,29] = 918000

matshow(matrix, norm=LogNorm(vmin=1, vmax=1000000))
colorbar()
show()

And if one specifies no limits to LogNorm, the colorbar displayed is incomplete and the colour displayed is wrong in a different way then when specifying the limits (try value = 999000 as well).

from pylab import *
from matplotlib.colors import LogNorm

matrix = ones((30,30))
matrix = matrix*440
matrix[29,29] = 918000

matshow(matrix, norm=LogNorm())
colorbar()
show()

Either I am completely missing something or there is a major bug.

I am using mpl checked out from svn on 26 March.

Thanks,
Suresh

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

I think the problems with imshow and matshow of integer arrays are fixed now in svn.

Eric

Suresh Pillai wrote:

···

So I been using the log scale provided by matplotlib.colors.LogNorm, but have been seing bizarre behaviour. Basically, high values are not displayed properly. I give simple examples below with just two possible values in the matrix, but all the same issues arise with more varied values.

First notice that the high value (100000) is displayed as being of value=1:

from pylab import *
from matplotlib.colors import LogNorm

matrix = ones((30,30))
matrix = matrix*440
matrix[29,29] = 100000

matshow(matrix, norm=LogNorm(vmin=1, vmax=1000000))
colorbar()
show()

The cutoff value for incorrect display (for the scale I am using) seems to be at 32000:

from pylab import *
from matplotlib.colors import LogNorm

matrix = ones((30,30))
matrix = matrix*440
matrix[29,29] = 32000

matshow(matrix, norm=LogNorm(vmin=1, vmax=1000000))
colorbar()
show()

However, if the value is really high, the color displayed changes again, although still not to the correct color (please try with values 918000, 920000, and 999000 to see see it progress):

from pylab import *
from matplotlib.colors import LogNorm

matrix = ones((30,30))
matrix = matrix*440
matrix[29,29] = 918000

matshow(matrix, norm=LogNorm(vmin=1, vmax=1000000))
colorbar()
show()

And if one specifies no limits to LogNorm, the colorbar displayed is incomplete and the colour displayed is wrong in a different way then when specifying the limits (try value = 999000 as well).

from pylab import *
from matplotlib.colors import LogNorm

matrix = ones((30,30))
matrix = matrix*440
matrix[29,29] = 918000

matshow(matrix, norm=LogNorm())
colorbar()
show()

Either I am completely missing something or there is a major bug.

I am using mpl checked out from svn on 26 March.

Thanks,
Suresh

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options