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

Setting limits containing zero in pub_plot #112

Open
chuaxr opened this issue Feb 29, 2024 · 1 comment
Open

Setting limits containing zero in pub_plot #112

chuaxr opened this issue Feb 29, 2024 · 1 comment

Comments

@chuaxr
Copy link

chuaxr commented Feb 29, 2024

I am getting unexpected behavior from limits containing zero when using pub_plot:

Here's an example trying to plot a sample file (created by cdo -f nc4 -topo,r24x12 topo.nc) with version 1.1.6.

python -c 'import nctoolkit;nctoolkit.open_data("topo.nc").pub_plot(var="topo",out="test0.png",mid_point=1,limits=[0,2])' gives a plot that does not have limits at [0,2].

test0

python -c 'import nctoolkit;nctoolkit.open_data("topo.nc").pub_plot(var="topo",out="test1.png",mid_point=1,limits=[-2,2])' also does not have limits at [-2,2].

test1

However,
python -c 'import nctoolkit;nctoolkit.open_data("topo.nc").pub_plot(var="topo",out="test2.png",mid_point=0,limits=[-2,2])' behaves as expected.

test2

My guess is that moving lines 464-466 in static_plot.py out of the try loop would help, and that mid_point=0 happens to work because of lines 530-533.

@robertjwilson
Copy link
Member

After some thought, the mid_point arg is poorly designed, and it probably should not exist.

In your case, you should probably specify the colour scale:
ds.pub_plot(var="topo",out="test0.png",mid_point=1,limits=[0,2], colours = "RdBu_r")

This is probably the easiest way to get the desired output.

I have now made some changes to the development version.

  1. mid_point is no longer an argument.
  2. If the limits is supplied, and the colour scale passes through zero, the colour scale will be forced to be symmetrical around zero. i.e. if you supply [-2, 10], it would be reset to [-10, 10].

A proper midpoint handling could be added in a future release (e.g. something like this: https://stackoverflow.com/questions/7404116/defining-the-midpoint-of-a-colormap-in-matplotlib).

I will leave the issue open.

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