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

Make bqplot linear scatter sizes more closely match matplotlib viewer #394

Merged
merged 3 commits into from
Sep 6, 2023

Conversation

Carifio24
Copy link
Member

This PR aims to resolve #392 by making the linear size scaling behave more similarly to that of the matplotlib viewer. To do this, I ended up not using the size scales for the layer, but rather following the matplotlib viewer's example and capping the size.

FWIW, my initial thought was to do something like

s = ensure_numerical(self.layer[self.state.size_att].ravel())
s = (s - self.state.size_vmin) / (self.state.size_vmax - self.state.size_vmin)
np.clip(s, self.state.size_vmin, self.state.size_vmax, out=s)
s *= 0.95
s += 0.05 * (self.state.size_vmax - self.state.size_vmin)
s *= self.scatter_mark.default_size
self.scatter_mark.size = s ** 2

self.scale_size_scatter.min = float_or_none(self.state.size_vmin ** 2)
self.scale_size_scatter.max = float_or_none(self.state.size_vmax ** 2)

but that gave results that differed from the matplotlib implementation when size_vmin was nonzero (like e.g. the example data in #392).

@dhomeier
Copy link
Contributor

dhomeier commented Aug 31, 2023

I suppose the image comparison failure is not unexpected, as the produced figure should look different now – have to update the reference image then. Do we only need to update

"glue_jupyter.bqplot.scatter.tests.test_visual.test_visual_scatter2d[chromium]": "3fe576be80889cc20063dd9e17f39899b2e40fb9a779eaa02e19b01181b332aa",
"glue_jupyter.bqplot.scatter.tests.test_visual.test_visual_scatter2d_density[chromium]": "f09681c1d9aea95612e4a268ab9ada15f5cb7c0158bfc5b13ccb0c890779feb2"

to

"edd4e65c87369bc6e403f45e87d914223bc13f42c2f90a55535614923e233c00"
"60f38b822f89603874cd508e0c320db92185129631dd89a58624dd667eb8a5a7"

then?

@dhomeier dhomeier added bug Something isn't working bqplot-viewers labels Aug 31, 2023
Comment on lines +272 to +278
self.scatter_mark.default_size = int(self.state.size_scaling * 7)
s = ensure_numerical(self.layer[self.state.size_att].ravel())
s = ((s - self.state.size_vmin) /
(self.state.size_vmax - self.state.size_vmin))
np.clip(s, 0, 1, out=s)
s *= 0.95
s += 0.05
Copy link
Contributor

Choose a reason for hiding this comment

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

Those numbers (size_scaling * 7, s ranging from 0.05 to 1.0) are taken from comparison with the matplotlib defaults?
I was wondering if the division by 0 in

scatter_density_mark.py:210: RuntimeWarning: invalid value encountered in divide
normalized_counts = (self._counts - vmin) / (vmax - vmin)

was related, but that warning already pops up prior to this PR – I suppose that's bad user input really.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, the 7 is a magic constant that I thought gave the closest match to the matplotlib layer artist - basically it's meant to serve a role similar what 30 does here.

Copy link
Contributor

Choose a reason for hiding this comment

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

If the parent LayerArtist is crafted that way, matching that makes sense. I'm good with the implantation so far, let's wait a little if @astrofrog has any comments.

@Carifio24
Copy link
Member Author

I'm not super familiar with the CircleCI system yet, but I think you're right that we just need to update the hashes. Once we're satisfied with all the code changes I'll take care of that.

@dhomeier
Copy link
Contributor

dhomeier commented Sep 5, 2023

Go ahead with updating the hashes if you wish; once the CI is fixed this should be good to go in for the 0.18.0 release.

@codecov
Copy link

codecov bot commented Sep 6, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.22% 🎉

Comparison is base (1e70916) 86.61% compared to head (807daee) 86.84%.
Report is 32 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #394      +/-   ##
==========================================
+ Coverage   86.61%   86.84%   +0.22%     
==========================================
  Files          89       89              
  Lines        4946     5077     +131     
==========================================
+ Hits         4284     4409     +125     
- Misses        662      668       +6     
Files Changed Coverage Δ
glue_jupyter/bqplot/scatter/layer_artist.py 91.00% <100.00%> (+0.14%) ⬆️

... and 6 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@dhomeier
Copy link
Contributor

dhomeier commented Sep 6, 2023

I'm not super familiar with the CircleCI system yet, but I think you're right that we just need to update the hashes. Once we're satisfied with all the code changes I'll take care of that.

Thanks! Struggling to make sense of it myself – image comparison is now passing with the expected hash, though the figure_report still shows a different (the original) baseline image. From the pytest invocation I take that the reference figures are pulled from https://github.com/glue-viz/glue-jupyter-visual-tests; this in turn seems to be automatically updated when a change in py311-test-visual.json is pushed to main, so I'd just merge and see if this works.

I was more worried about the docs build still failing, but seeing now that readthedocs tries to use an obsolete .readthedocs.yml with Python 3.6. Should have rebased to pull in #386, but I think this will also sort itself out on merging.

@dhomeier dhomeier changed the title Make linear sizes more closely match matplotlib viewer Make bqplot linear scatter sizes more closely match matplotlib viewer Sep 6, 2023
@dhomeier dhomeier merged commit 60f58c3 into glue-viz:main Sep 6, 2023
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bqplot-viewers bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Disparity in linear scatter size between matplotlib and bqplot viewers
2 participants