colormap clipping for large numbers (small vmax - vmin)

I was using pcolor with very large numbers and a small vrange (vmax - vmin), and ran into a float to integer conversion problem. Large numbers get converted to negative integers by astype (see numpy thread) in colors.Colormap.call.

I’m not sure if this is even worth fixing since almost no one would run into this problem (unless you were doing something stupid, like trying to use pcolor as a 2D zero finder :). For the error to occur, you have to set vmin/vmax values (otherwise, the data is properly normalized before converting to integers), and your data has to greatly exceed these limits.

Cheers,

-Tony

clip_vs_putmask.py (355 Bytes)

Sorry, I attached the wrong file:

colormap_clipping.patch (702 Bytes)

Tony S Yu wrote:

I was using pcolor with very large numbers and a small vrange (vmax - vmin), and ran into a float to integer conversion problem. Large numbers get converted to *negative* integers by astype (see numpy thread <http://projects.scipy.org/pipermail/numpy-discussion/2008-October/038159.html>) in colors.Colormap.__call__.

I'm not sure if this is even worth fixing since almost no one would run into this problem (unless you were doing something stupid, like trying to use pcolor as a 2D zero finder :). For the error to occur, you have to set vmin/vmax values (otherwise, the data is properly normalized before converting to integers), and your data has to greatly exceed these limits.

Tony,

Thank you.

I committed the change; it looks like the cost of the extra clip is negligible, and it is nice to make the behavior correct even under extreme conditions.

Eric

···

Cheers,
-Tony

------------------------------------------------------------------------

Example of the problem:
#~~~~~~~~~~~~~
import matplotlib.pyplot as plt
import numpy as np

cmap = plt.cm.gray
cmap.set_over('r', 1.0)
cmap.set_under('g', 1.0)
cmap.set_bad('b', 1.0)

eps = 1E-8

A = np.arange(100).reshape(10, 10)
plt.pcolor(A, vmin=50, vmax=50+eps, cmap=cmap)
# the plot should be about half red and half green (plus a black square)
# without patch, some of the red squares are filled green
plt.show()
#~~~~~~~~~~~~~

------------------------------------------------------------------------

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/

------------------------------------------------------------------------

_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel