Thanks to visit codestin.com
Credit goes to github.com

Skip to content

PowerNorm().__call__ doesn't work with scalar input value #4053

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
olegarch opened this issue Jan 29, 2015 · 8 comments
Closed

PowerNorm().__call__ doesn't work with scalar input value #4053

olegarch opened this issue Jan 29, 2015 · 8 comments
Assignees
Milestone

Comments

@olegarch
Copy link

result[value<0] = 0; #fails if value is scalar

@tacaswell
Copy link
Member

Can you provide a bit for context to what is going on here? It is best if you can include an example that can be copy-paste run (http://sscce.org/) and the traceback produced.

@tacaswell tacaswell added the status: needs clarification Issues that need more information to resolve. label Jan 30, 2015
@tacaswell tacaswell added this to the unassigned milestone Jan 30, 2015
@olegarch
Copy link
Author

Python 2.7.6

=================== Sample starts here =============

#!/usr/bin/env python

import matplotlib
import matplotlib.pyplot

min,max = (1,100)
cm = matplotlib.pyplot.get_cmap('jet') 
cNorm0 = matplotlib.colors.Normalize(vmin=min, vmax=max)
cNorm1 = matplotlib.colors.LogNorm(vmin=min, vmax=max)
cNorm2 = matplotlib.colors.PowerNorm(1.,vmin=min, vmax=max,clip=True)
scalarMap0 = matplotlib.cm.ScalarMappable(norm=cNorm0, cmap=cm)
scalarMap1 = matplotlib.cm.ScalarMappable(norm=cNorm1, cmap=cm)
scalarMap2 = matplotlib.cm.ScalarMappable(norm=cNorm2, cmap=cm)

value = 50.
print "min,max",min,max
print "RGB for Normalize(50)", scalarMap0.to_rgba(value)
print "RGB for LogNorm(50)", scalarMap1.to_rgba(value)
print "RGB for PowerNorm(50)", scalarMap2.to_rgba([value])[0]
print "RGB for PowerNorm(50)", scalarMap2.to_rgba(value)

============== Sample ends here ==================

Output:

$ ./powernorm.py
min,max 1 100
RGB for Normalize(50) (0.46489563567362424, 1.0, 0.50284629981024676, 1.0)
RGB for LogNorm(50) (1.0, 0.21859114015976777, 0.0, 1.0)
RGB for PowerNorm(50) [ 0.46489564  1.          0.5028463   1.        ]
RGB for PowerNorm(50)
Traceback (most recent call last):
  File "./powernorm.py", line 20, in <module>
    print "RGB for PowerNorm(50)", scalarMap2.to_rgba(value)
  File "C:\Python27\lib\site-packages\matplotlib\cm.py", line 262, in to_rgba
    x = self.norm(x)
  File "C:\Python27\lib\site-packages\matplotlib\colors.py", line 1180, in __call__
    result[value < 0] = 0
  File "C:\Python27\lib\site-packages\numpy\ma\core.py", line 3072, in __setitem__
    ndarray.__setitem__(_data, indx, dval)
ValueError: boolean index array should have 1 dimension

[TAC edited to add markup]

@WeatherGod
Copy link
Member

Which version of matplotlib? I could have sworn we fixed this.

By the way, with my matplotlib from (slightly old) trunk and numpy version
1.9.0:

scalarMap2.to_rgba(50.0)
Traceback (most recent call last):
File "", line 1, in
File
"/nas/home/broot/centos6/lib/python2.7/site-packages/matplotlib-1.5.x-py2.7-linux-x86_64.egg/matplotlib/cm.py",
line 263, in to_rgba
x = self.norm(x)
File
"/nas/home/broot/centos6/lib/python2.7/site-packages/matplotlib-1.5.x-py2.7-linux-x86_64.egg/matplotlib/colors.py",
line 1189, in call
result[value < 0] = 0
File
"/nas/home/broot/centos6/lib/python2.7/site-packages/numpy/ma/core.py",
line 3079, in setitem
ndarray.setitem(_data, indx, dval)
IndexError: in the future, 0-d boolean arrays will be interpreted as a
valid boolean index

So, I don't know if this is a weird interaction or not with numpy.

On Fri, Jan 30, 2015 at 1:35 AM, olegarch [email protected] wrote:

Python 2.7.6

=================== Sample starts here =============
#!/usr/bin/env python

import matplotlib
import matplotlib.pyplot

min,max = (1,100)
cm = matplotlib.pyplot.get_cmap('jet')
cNorm0 = matplotlib.colors.Normalize(vmin=min, vmax=max)
cNorm1 = matplotlib.colors.LogNorm(vmin=min, vmax=max)
cNorm2 = matplotlib.colors.PowerNorm(1.,vmin=min, vmax=max,clip=True)
scalarMap0 = matplotlib.cm.ScalarMappable(norm=cNorm0, cmap=cm)
scalarMap1 = matplotlib.cm.ScalarMappable(norm=cNorm1, cmap=cm)
scalarMap2 = matplotlib.cm.ScalarMappable(norm=cNorm2, cmap=cm)

value = 50.
print "min,max",min,max
print "RGB for Normalize(50)", scalarMap0.to_rgba(value)
print "RGB for LogNorm(50)", scalarMap1.to_rgba(value)
print "RGB for PowerNorm(50)", scalarMap2.to_rgba([value])[0]
print "RGB for PowerNorm(50)", scalarMap2.to_rgba(value)
============== Sample ends here ==================

Output:
$ ./powernorm.py
min,max 1 100
RGB for Normalize(50) (0.46489563567362424, 1.0, 0.50284629981024676, 1.0)
RGB for LogNorm(50) (1.0, 0.21859114015976777, 0.0, 1.0)
RGB for PowerNorm(50) [ 0.46489564 1. 0.5028463 1. ]
RGB for PowerNorm(50)
Traceback (most recent call last):
File "./powernorm.py", line 20, in
print "RGB for PowerNorm(50)", scalarMap2.to_rgba(value)
File "C:\Python27\lib\site-packages\matplotlib\cm.py", line 262, in to_rgba
x = self.norm(x)
File "C:\Python27\lib\site-packages\matplotlib\colors.py", line 1180, in
call
result[value < 0] = 0
File "C:\Python27\lib\site-packages\numpy\ma\core.py", line 3072, in
setitem
ndarray.setitem(_data, indx, dval)
ValueError: boolean index array should have 1 dimension


Reply to this email directly or view it on GitHub
#4053 (comment)
.

tacaswell added a commit to tacaswell/matplotlib that referenced this issue Jan 30, 2015
@tacaswell tacaswell self-assigned this Jan 30, 2015
@tacaswell
Copy link
Member

have a fix in + extended the tests.

At some point we should go through and simplify all of that code to use arrays filled with nans internally rather than masked arrays.

@tacaswell tacaswell added status: confirmed bug and removed status: needs clarification Issues that need more information to resolve. labels Jan 30, 2015
@tacaswell tacaswell modified the milestones: v1.4.3, unassigned Jan 30, 2015
@tacaswell
Copy link
Member

@olegarch Thanks! If possible can you confirm that this fixes the issue for you?

@olegarch
Copy link
Author

olegarch commented Feb 2, 2015

It works. Thanks!

@tacaswell
Copy link
Member

@olegarch Good. This fix will be in 1.4.3 (tagged a release candidate last night, should do full release next weekend).

@tacaswell
Copy link
Member

@olegarch Good to hear.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants