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

[BUG/ISSUE] Colorbar ticks are incorrectly placed if the plot is zero or undefined everywhere. #37

Closed
yantosca opened this issue Sep 10, 2019 · 2 comments
Assignees
Labels
category: Bug Something isn't working

Comments

@yantosca
Copy link
Contributor

Describe the bug

It seems that newer versions of Matplotlib (since 3.0 or 3.1) cause colorbar ticks to be placed incorrectly for plots that are zero everywhere or undefined everywhere

cb1

This is probably caused in the normalization of colors in the from the min and max of the data range to the matplotlib color scale.

@yantosca
Copy link
Contributor Author

This issue is now resolved in 1c7647a. We now test whether or not we are using matplotlib 3.1.1 or an older version, and adjust the tickmark placement accordingly.

@yantosca yantosca reopened this Sep 12, 2019
@yantosca
Copy link
Contributor Author

I have now pushed commit: f450fe2, which definitively fixes this issue.

The problem was not so much matplotlib 3.1.1 vs. older versions,. Instead, if we use the RdBu colortable (as we do for diff-of-diffs plots, like the one shown above), then we must take care to place the tick in the middle of the colorbar if Ref and/or Dev is zero or undefined everywhere. I modified the code in the if all_zero or all_undefined blocks accordingly.

        if all_zero or all_undefined:
            if use_cmap_RdBu:
                cb.set_ticks([0.0])
            else:
                cb.set_ticks([0.5])

This now produces the proper tick placement for RdBu difference color map:
test1

As well as the non-difference color map WhGrYlRd:
test2

@yantosca yantosca self-assigned this Oct 17, 2019
@yantosca yantosca added category: Bug Something isn't working resolved labels Oct 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant