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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions glue_jupyter/bqplot/scatter/layer_artist.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,9 @@ def __init__(self, view, viewer_state, layer_state=None, layer=None):

# Scatter points

self.scale_size_scatter = bqplot.LinearScale()
self.scale_color_scatter = bqplot.ColorScale()
self.scales_scatter = dict(
self.view.scales,
size=self.scale_size_scatter,
color=self.scale_color_scatter,
)

Expand Down Expand Up @@ -270,15 +268,16 @@ def _update_visual_attributes(self, changed, force=False):
self.state.size * self.state.size_scaling,
)
self.scatter_mark.size = None
self.scale_size_scatter.min = 0
self.scale_size_scatter.max = 1
else:
self.scatter_mark.default_size = int(self.state.size_scaling * 25)
self.scatter_mark.size = ensure_numerical(
self.layer[self.state.size_att].ravel()
)
self.scale_size_scatter.min = float_or_none(self.state.size_vmin)
self.scale_size_scatter.max = float_or_none(self.state.size_vmax)
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
Comment on lines +272 to +278
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.

s *= self.scatter_mark.default_size
self.scatter_mark.size = s ** 2

if (
self.state.vector_visible
Expand Down
6 changes: 3 additions & 3 deletions glue_jupyter/tests/images/py311-test-visual.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"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"
}
"glue_jupyter.bqplot.scatter.tests.test_visual.test_visual_scatter2d[chromium]": "edd4e65c87369bc6e403f45e87d914223bc13f42c2f90a55535614923e233c00",
"glue_jupyter.bqplot.scatter.tests.test_visual.test_visual_scatter2d_density[chromium]": "60f38b822f89603874cd508e0c320db92185129631dd89a58624dd667eb8a5a7"
}