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

vmin=0 in 2d histograms #157

Merged
merged 4 commits into from
Apr 23, 2021
Merged

Conversation

lukashergt
Copy link
Collaborator

@lukashergt lukashergt commented Apr 10, 2021

This addresses #156 which pointed out that vmin in 2d histograms needs to be set to zero in order for uniform distributions to appear uniform.

Fixes #156

Checklist:

  • I have performed a self-review of my own code
  • My code is PEP8 compliant (flake8 anesthetic tests)
  • My code contains compliant docstrings (pydocstyle --convention=numpy anesthetic)
  • New and existing unit tests pass locally with my changes (python -m pytest)
  • I have added tests that prove my fix is effective or that my feature works

@lukashergt lukashergt self-assigned this Apr 10, 2021
@@ -787,7 +788,8 @@ def hist_plot_2d(ax, data_x, data_y, *args, **kwargs):
pdf[pdf < cmin] = np.ma.masked
if cmax is not None:
pdf[pdf > cmax] = np.ma.masked
image = ax.pcolormesh(x, y, pdf.T, cmap=cmap, vmin=0, vmax=pdf.max(),
image = ax.pcolormesh(x, y, pdf.T, cmap=cmap,
vmin=vmin, vmax=pdf.max(),
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we actually need the vmax=pdf.max() here? Could we remove it such that if someone wanted to fix it for some reason this would be possible?

If we do need it, do we also need it for ax.hist2d further up?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to normalize the histogram like in the 1d case and set vmax=1 by default? That would make the maximum consistent across a triangle plot (keeping in mind that in most cases there won't be a colorbar to go alongside the plot).

@Stefan-Heimersheim, @williamjameshandley: Thoughts?

Copy link
Collaborator

@Stefan-Heimersheim Stefan-Heimersheim Apr 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vmax=pdf.max()

This seems to be the default in pcolormesh

vmin, vmax: float, default: None
The colorbar range. If None, suitable min/max values are automatically chosen by the Normalize instance (defaults to the respective min/max values of C in case of the default linear scaling). It is deprecated to use vmin/vmax when norm is given.

So I think we can just leave the default if it doesn't do anything. Edit: Same for hist2d via Normalize

Would it make sense to normalize the histogram like in the 1d case and set vmax=1 by default?

Doesn't this interfere with the y-axis in double-triangle plots where the y axis is actually relevant for the upper triangle and not necessarily 0 to 1?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the maximum consistent across a triangle plot (keeping in mind that in most cases there won't be a colorbar to go alongside the plot).

Oh I misunderstood the vmax=1 idea. I see the idea, but I think it might be difficult if some PDFs are much narrower than others. Say you have N(sigma=0.1) and N(sigma=1) [not too uncommon], then the 2nd PDF would peak at most at 10% of the height of the plot and be very hard to read.

Thanks Lukas for making the PR!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking about it, I don't know anymore why I suggested that. Normalizing to maximum and setting vmax=1 is no different to setting vmax=pdf.max() in all plots, so no need for that.

But I do think that vmax=pdf.max() is the default anyhow, so we don't need to code it in there and by not putting it in explicitly we allow for vmax to be overwritten if desired, right? I've removed it in babcf52.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Stefan-Heimersheim, could you confirm this achieves what you want, and if so approve the review so @lukashergt can squash and merge

@codecov
Copy link

codecov bot commented Apr 23, 2021

Codecov Report

Merging #157 (7bd78d4) into master (743e09e) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #157   +/-   ##
=======================================
  Coverage   94.98%   94.98%           
=======================================
  Files          16       16           
  Lines        1614     1615    +1     
=======================================
+ Hits         1533     1534    +1     
  Misses         81       81           
Impacted Files Coverage Δ
anesthetic/plot.py 97.55% <100.00%> (+<0.01%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 743e09e...7bd78d4. Read the comment docs.

Copy link
Collaborator

@Stefan-Heimersheim Stefan-Heimersheim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this works as intended in all my applications!

@lukashergt lukashergt merged commit 9fd0de1 into handley-lab:master Apr 23, 2021
@lukashergt lukashergt deleted the hist2d_vmin branch April 14, 2023 21:38
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

Successfully merging this pull request may close these issues.

Suggestion to make vmin=0 the default for histograms
3 participants