Skip to content
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

Colorbar autoscale handling an array of one value #2347

Closed
gurglespuge opened this issue Aug 27, 2013 · 5 comments
Closed

Colorbar autoscale handling an array of one value #2347

gurglespuge opened this issue Aug 27, 2013 · 5 comments
Milestone

Comments

@gurglespuge
Copy link

When plotting with imshow an array with all one value.

a = ones((10,10))
imshow(a)
colorbar()
show()

colorbar.py:829: RuntimeWarning: invalid value encountered in divide
z = np.take(y, i0) + (xn - np.take(b, i0)) * dy / db

The output is thus:

figure_1

I realize this is a corner case, but it would be very useful for the colorbar auto scale to somehow indicate the value.

Putting this code into colorbar.py
_locate function

immediately before the return(z) call

if np.isnan(z).any():$                                                 
    z = np.array(range(1,len(x)))/float(len(x))$  

remedies the problem for me.

I can send a patch file for fork, if anyone is interested.

I presume this is not the best way to remedy the issue for matplotlib proper, probably better to detect the condition earlier and deal with it, then screen for nan's

@tacaswell
Copy link
Member

The correct place to fix this is where vmax and vmin are calculated and expand them if they are equal. I could have sworn we already fixed this...There may be an un-merged PR floating around that addresses this.

@tacaswell
Copy link
Member

Closing this because it is the same issue as #2642 .

@gurglespuge If you can put together that PR that would be great!

@ghost
Copy link

ghost commented May 8, 2015

I'm rather new to this site, but did this issue ever get resolved? I'm trying to use colorbar on arrays with the same value over most positions. I'm getting the error message discussed above and tried the

if np.isnan(z).any():$
z = np.array(range(1,len(x)))/float(len(x))$

tip, but still have an error message. Any help with this would be great.

@WeatherGod
Copy link
Member

I think so, I can't reproduce it using code from the master branch. Which version of matplotlib are you using?

@ghost
Copy link

ghost commented May 8, 2015

I'm using matplotlib 1.3.0.

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

No branches or pull requests

3 participants