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

[FR] symmetric contour levels, the ability to ignore the actual values. #4807

Closed
ryofurue opened this issue Aug 24, 2023 · 5 comments
Closed

Comments

@ryofurue
Copy link

I often need to plot positive and negative values with reddish and bluish colors because the signs are important; also I need to respect the magnitude (I mean, for example, "3" and "-3" should have red and blue colors with the "same" "strength". There are well designed color palettes like redsblues suitable for this task, except that the contour() function doesn't allow the user to specify symmetric contour levels:

using Plots
xs=-5:1:5
ys=-5:1:5
var = [ x^2 + y^2 - 15.0 for x in xs, y in ys]
p = contourf(xs, ys, var; color=:redsblues, levels=-40:10:40)
display(p)

Here I want the contour levels to be [-40, -30, . . ., 0, . . . , 30, 40] but the contour function overrides my wish and adjusts the contour levels to the actual value range of the variable, which is -15 < z < 35.

@BeastyBlacksmith
Copy link
Member

Setting clims = (-40,40) should give you that

@ryofurue
Copy link
Author

ryofurue commented Aug 25, 2023

Setting clims = (-40,40) should give you that

Indeed! Thanks, but I didn't mean to use this issue tracker as if it were a help forum!

But, this indicates that there is another bug. Let's use this modified example:

using Plots
#plotly() # GR doesn't support open ended contour levels
xs=-5:1:5
ys=-5:1:5
var = [ x^2 + y^2 - 15.0 for x in xs, y in ys]
#p = contourf(xs, ys, var; color=:redsblues, levels=-20:10:20)
p = contourf(xs, ys, var; color=:redsblues, clims=(-20,20) )
display(p)

With GR,

  1. lev=-20:10:20 crashes the program.
  2. clims=(-20,20) gives a correct plot with symmetric contour levels, except the colorbar indicates as if only the range -20 < z < 20 were plotted, whereas the contour plot itself paints values beyond ±20. The colorbar should indicate the open-ended-ness of the contour levels.

I think I reported issue 1 as a separate bug. Should I report issue 2 as well?

With Plotly,

  1. lev=-20:10:20 creates a correct plot with symmetric contour levels. The colorbar indicates the open-ended-ness of the levels.
  2. clims=(-20,20) gives a similarly correct plot as the lev example.

So, I guess that GR should be modified to behave exactly like Plotly in this regard?

@BeastyBlacksmith
Copy link
Member

Should I report issue 2 as well?

I'd say that is pretty much the same as #4805, no?

@ryofurue
Copy link
Author

ryofurue commented Aug 25, 2023

Should I report issue 2 as well?

I'd say that is pretty much the same as #4805, no?

I don't think so. #4805 is just a "nice features to have". It's not a bug.

But issue 2 above is a bug. The following plot indicates that all the values are within the range -20 < z < 20:

using Plots
xs=-5:1:5
ys=-5:1:5
var = [ x^2 + y^2 - 15.0 for x in xs, y in ys]
p = contourf(xs, ys, var; color=:redsblues, clims=(-20,20) )
display(p)

The fact is the variable includes values larger than 20. If you compare the plot and the colarbar, you'll see that the color for 15 < z < 20 is used to plot z > 20. I would say this colorbar is incorrect.

For this reason, this plot cannot be used in a scientific paper.

@ryofurue
Copy link
Author

So, I've just created a new issue: #4813

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

2 participants