Skip to content

Commit

Permalink
Merge pull request #78 from Carifio24/axis-lines
Browse files Browse the repository at this point in the history
Show axis lines
  • Loading branch information
Carifio24 authored Jul 9, 2024
2 parents c3099cf + dfb1c18 commit 8a3f1b3
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 7 deletions.
2 changes: 1 addition & 1 deletion glue_plotly/viewers/histogram/tests/test_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def test_axes(self):
assert all(f.family == DEFAULT_FONT for f in
(x_axis.title.font, x_axis.tickfont, y_axis.title.font, y_axis.tickfont))

common_items = dict(showgrid=False, showline=False, mirror=True, rangemode='normal',
common_items = dict(showgrid=False, showline=True, mirror=True, rangemode='normal',
zeroline=False, showspikes=False, showticklabels=True)
for axis in x_axis, y_axis:
assert all(axis[key] == value for key, value in common_items.items())
Expand Down
2 changes: 0 additions & 2 deletions glue_plotly/viewers/histogram/viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ def _create_layout_config(self):
width=1000, height=600,
**self.LAYOUT_SETTINGS)
x_axis = base_rectilinear_axis(self.state, 'x')
x_axis.update(showline=False)
y_axis = base_rectilinear_axis(self.state, 'y')
y_axis.update(showline=False)
config.update(xaxis=x_axis, yaxis=y_axis)
return config

Expand Down
Empty file.
66 changes: 66 additions & 0 deletions glue_plotly/viewers/scatter/tests/test_viewer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
from numpy import array_equal

from glue.core import Data
from glue_jupyter import JupyterApplication
from plotly.graph_objects import Scatter

from glue_plotly.common import DEFAULT_FONT
from glue_plotly.viewers.scatter import PlotlyScatterView


class TestScatterView:

def setup_method(self, method):
self.data = Data(label="histogram", x=[1, 3, 5, 7, 9], y=[2, 4, 6, 8, 10])
self.app = JupyterApplication()
self.app.session.data_collection.append(self.data)
self.viewer = self.app.new_data_viewer(PlotlyScatterView)
self.viewer.add_data(self.data)

viewer_state = self.viewer.state
viewer_state.x_min = 0
viewer_state.x_max = 10
viewer_state.y_min = 0
viewer_state.y_max = 12
viewer_state.x_axislabel = 'X Axis'
viewer_state.y_axislabel = 'Y Axis'
viewer_state.normalize = False

self.layer = self.viewer.layers[0]
self.layer.state.color = "#abcdef"
self.layer.state.alpha = 0.75

def teardown_method(self, method):
self.viewer = None
self.app = None

def test_basic(self):
assert len(self.viewer.layers) == 1
traces = list(self.layer.traces())
assert len(traces) == 1
scatter = traces[0]
assert isinstance(scatter, Scatter)
assert scatter.marker.color == "#abcdef"
assert scatter.marker.opacity == 0.75
assert array_equal(scatter.x, self.data['x'])
assert array_equal(scatter.y, self.data['y'])

def test_axes(self):
x_axis = self.viewer.figure.layout.xaxis
y_axis = self.viewer.figure.layout.yaxis

assert x_axis.title.text == 'X Axis'
assert y_axis.title.text == 'Y Axis'
assert x_axis.type == 'linear'
assert y_axis.type == 'linear'

assert x_axis.range == (0, 10)
assert y_axis.range == (0, 12)

assert all(f.family == DEFAULT_FONT for f in
(x_axis.title.font, x_axis.tickfont, y_axis.title.font, y_axis.tickfont))

common_items = dict(showgrid=False, showline=True, mirror=True, rangemode='normal',
zeroline=False, showspikes=False, showticklabels=True)
for axis in x_axis, y_axis:
assert all(axis[key] == value for key, value in common_items.items())
5 changes: 1 addition & 4 deletions glue_plotly/viewers/scatter/viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,7 @@ def __init__(self, *args, **kwargs):

def _create_layout_config(self):
if self.state.using_rectilinear:
config = rectilinear_layout_config(self, **self.LAYOUT_SETTINGS)
config['xaxis']['showline'] = False
config['yaxis']['showline'] = False
return config
return rectilinear_layout_config(self, **self.LAYOUT_SETTINGS)
else: # For now, that means polar
return polar_layout_config(self, radial_axis, **self.LAYOUT_SETTINGS)

Expand Down

0 comments on commit 8a3f1b3

Please sign in to comment.