Skip to content

Commit

Permalink
Merge pull request #2467 from astrofrog/fix-default-stretch-density
Browse files Browse the repository at this point in the history
Fix default stretch density
  • Loading branch information
astrofrog authored Dec 7, 2023
2 parents 312aeb4 + 47b18aa commit 6cdad79
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 6 deletions.
13 changes: 7 additions & 6 deletions glue/tests/visual/py311-test-visual.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"glue.viewers.histogram.tests.test_viewer.test_simple_viewer": "cb08123fbad135ab614bb7ec13475fcc83321057d884fe80c3a32970b2d14762",
"glue.viewers.image.tests.test_viewer.test_simple_viewer": "72abd60b484d14f721254f027bb0ab9b36245d5db77eb87693f4dd9998fd28be",
"glue.viewers.profile.tests.test_viewer.test_simple_viewer": "f68a21be5080fec513388b2d2b220512e7b0df5498e2489da54e58708de435b3",
"glue.viewers.scatter.tests.test_viewer.test_simple_viewer": "1020a7bd3abe40510b9e03047c3b423b75c3c64ac18e6dcd6257173cec1ed53f",
"glue.viewers.image.tests.test_viewer.test_region_layer": "b54088d1f31562d309d35c5e90c0a382c7ba4c16cc0db8134e9532f71f047076"
}
"glue.viewers.histogram.tests.test_viewer.test_simple_viewer": "cb08123fbad135ab614bb7ec13475fcc83321057d884fe80c3a32970b2d14762",
"glue.viewers.image.tests.test_viewer.test_simple_viewer": "72abd60b484d14f721254f027bb0ab9b36245d5db77eb87693f4dd9998fd28be",
"glue.viewers.image.tests.test_viewer.test_region_layer": "b54088d1f31562d309d35c5e90c0a382c7ba4c16cc0db8134e9532f71f047076",
"glue.viewers.profile.tests.test_viewer.test_simple_viewer": "f68a21be5080fec513388b2d2b220512e7b0df5498e2489da54e58708de435b3",
"glue.viewers.scatter.tests.test_viewer.test_simple_viewer": "1020a7bd3abe40510b9e03047c3b423b75c3c64ac18e6dcd6257173cec1ed53f",
"glue.viewers.scatter.tests.test_viewer.test_scatter_density_map": "3379d655262769a6ccbdbaf1970bffa9237adbec23a93d3ab75da51b9a3e7f8b"
}
1 change: 1 addition & 0 deletions glue/viewers/scatter/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ def __init__(self, viewer_state=None, layer=None, **kwargs):
ScatterLayerState.vector_origin.set_display_func(self, vector_origin_display.get)

self.setup_stretch_callback()
self.stretch = 'log'

if self.viewer_state is not None:
self.viewer_state.add_callback('x_att', self._on_xy_change, priority=10000)
Expand Down
44 changes: 44 additions & 0 deletions glue/viewers/scatter/tests/test_viewer.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import numpy as np
from numpy.testing import assert_allclose

import matplotlib.pyplot as plt

from glue.tests.visual.helpers import visual_test

from glue.viewers.scatter.viewer import SimpleScatterViewer
from glue.core.application_base import Application
from glue.core.data import Data
from glue.core.link_helpers import LinkSame


@visual_test
Expand All @@ -29,6 +32,47 @@ def test_simple_viewer():
return viewer.figure


@visual_test
def test_scatter_density_map():

# Test the scatter density map

np.random.seed(12345)

app = Application()

x = np.random.normal(3, 1, 100)
y = np.random.normal(2, 1.5, 100)
c = np.hypot(x - 3, y - 2)
s = (x - 3)

data1 = app.add_data(a={"x": x, "y": y, "c": c, "s": s})[0]

xx = np.random.normal(3, 1, 1000000)
yy = np.random.normal(2, 1.5, 1000000)

data2 = app.add_data(a={"x": xx, "y": yy})[0]

app.data_collection.add_link(LinkSame(data1.id['x'], data2.id['x']))
app.data_collection.add_link(LinkSame(data1.id['y'], data2.id['y']))

viewer = app.new_data_viewer(SimpleScatterViewer)
viewer.add_data(data1)
viewer.add_data(data2)

viewer.state.layers[0].cmap_mode = 'Linear'
viewer.state.layers[0].cmap_att = data1.id['c']
viewer.state.layers[0].cmap = plt.cm.viridis
viewer.state.layers[0].size_mode = 'Linear'
viewer.state.layers[0].size_att = data1.id['s']

viewer.state.layers[1].zorder = 0.5

app.data_collection.new_subset_group(label='subset1', subset_state=data1.id['x'] > 2)

return viewer.figure


def test_reset_limits():

data1 = Data(x=np.arange(1000), y=np.arange(1000) + 1000, label='data')
Expand Down

0 comments on commit 6cdad79

Please sign in to comment.