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

Added support for controlling whether markers are filled or not. #1559

Merged
merged 3 commits into from
Mar 5, 2018
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
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ v0.13.0 (unreleased)
* Improve hiding/showing of side-panels. No longer hide side-panels
when glue application goes out of focus. [#1535]

* Added support for whether symbols are shown filled or not. [#1559]

* Improved link editor to include a graph of links. [#1534]

* Improve mouse interaction with ROIs in image viewers, including
Expand Down
1 change: 1 addition & 0 deletions glue/viewers/matplotlib/qt/tests/test_python_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def assert_same(self, tmpdir, tol=0.1):
exec(f.read())

msg = compare_images(expected, actual, tol=tol)

if msg:

from base64 import b64encode
Expand Down
32 changes: 24 additions & 8 deletions glue/viewers/scatter/layer_artist.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
'log': LogStretch}

CMAP_PROPERTIES = set(['cmap_mode', 'cmap_att', 'cmap_vmin', 'cmap_vmax', 'cmap'])
MARKER_PROPERTIES = set(['size_mode', 'size_att', 'size_vmin', 'size_vmax', 'size_scaling', 'size'])
MARKER_PROPERTIES = set(['size_mode', 'size_att', 'size_vmin', 'size_vmax', 'size_scaling', 'size', 'fill'])
LINE_PROPERTIES = set(['linewidth', 'linestyle'])
DENSITY_PROPERTIES = set(['dpi', 'stretch', 'density_contrast'])
VISUAL_PROPERTIES = (CMAP_PROPERTIES | MARKER_PROPERTIES | DENSITY_PROPERTIES |
Expand Down Expand Up @@ -336,8 +336,13 @@ def _update_visual_attributes(self, changed, force=False):

if self.state.cmap_mode == 'Fixed' and self.state.size_mode == 'Fixed':

if force or 'color' in changed:
self.plot_artist.set_color(self.state.color)
if force or 'color' in changed or 'fill' in changed:
if self.state.fill:
self.plot_artist.set_markeredgecolor('none')
self.plot_artist.set_markerfacecolor(self.state.color)
else:
self.plot_artist.set_markeredgecolor(self.state.color)
self.plot_artist.set_markerfacecolor('none')

if force or 'size' in changed or 'size_scaling' in changed:
self.plot_artist.set_markersize(self.state.size *
Expand All @@ -351,13 +356,24 @@ def _update_visual_attributes(self, changed, force=False):
force = True

if self.state.cmap_mode == 'Fixed':
if force or 'color' in changed or 'cmap_mode' in changed:
self.scatter_artist.set_facecolors(self.state.color)
self.scatter_artist.set_edgecolor('none')
elif force or any(prop in changed for prop in CMAP_PROPERTIES):
if force or 'color' in changed or 'cmap_mode' in changed or 'fill' in changed:
if self.state.fill:
self.scatter_artist.set_facecolors(self.state.color)
self.scatter_artist.set_edgecolors('none')
else:
self.scatter_artist.set_facecolors('none')
self.scatter_artist.set_edgecolors(self.state.color)
elif force or any(prop in changed for prop in CMAP_PROPERTIES) or 'fill' in changed:
self.scatter_artist.set_edgecolors(None)
self.scatter_artist.set_facecolors(None)
c = self.layer[self.state.cmap_att].ravel()
set_mpl_artist_cmap(self.scatter_artist, c, self.state)
self.scatter_artist.set_edgecolor('none')
if self.state.fill:
self.scatter_artist.set_edgecolors('none')
else:
colors = self.scatter_artist.get_facecolors()
self.scatter_artist.set_facecolors('none')
self.scatter_artist.set_edgecolors(colors)

if force or any(prop in changed for prop in MARKER_PROPERTIES):

Expand Down
23 changes: 18 additions & 5 deletions glue/viewers/scatter/python_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,15 @@ def python_export_scatter_layer(layer, *args):
if layer.state.cmap_mode == 'Fixed' and layer.state.size_mode == 'Fixed':
options = dict(color=layer.state.color,
markersize=layer.state.size * layer.state.size_scaling,
mec='none',
alpha=layer.state.alpha,
zorder=layer.state.zorder)
if layer.state.fill:
options['mec'] = 'none'
else:
options['mfc'] = 'none'
script += "ax.plot(x, y, 'o', {0})\n\n".format(serialize_options(options))
else:
options = dict(edgecolor='none',
alpha=layer.state.alpha,
options = dict(alpha=layer.state.alpha,
zorder=layer.state.zorder)

if layer.state.cmap_mode == 'Fixed':
Expand All @@ -96,10 +98,21 @@ def python_export_scatter_layer(layer, *args):
else:
options['s'] = code('sizes ** 2')

if layer.state.fill:
options['edgecolor'] = 'none'
else:
script += "s = "

if MATPLOTLIB_LT_20:
script += "ax.scatter(x[keep], y[keep], {0})\n\n".format(serialize_options(options))
script += "ax.scatter(x[keep], y[keep], {0})\n".format(serialize_options(options))
else:
script += "ax.scatter(x, y, {0})\n\n".format(serialize_options(options))
script += "ax.scatter(x, y, {0})\n".format(serialize_options(options))

if not layer.state.fill:
script += "s.set_edgecolors(s.get_facecolors())\n"
script += "s.set_facecolors('none')\n"

script += "\n"

if layer.state.vector_visible:

Expand Down
2 changes: 2 additions & 0 deletions glue/viewers/scatter/qt/layer_style_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ def _update_size_mode(self, size_mode=None):
self.ui.value_size_scaling.setVisible(not density)
self.ui.label_size_mode.setVisible(not density)
self.ui.label_size_scaling.setVisible(not density)
self.ui.label_fill.setVisible(not density)
self.ui.bool_fill.setVisible(not density)

def _update_markers_visible(self, *args):
self.ui.combosel_size_mode.setEnabled(self.layer_state.markers_visible)
Expand Down
25 changes: 24 additions & 1 deletion glue/viewers/scatter/qt/layer_style_editor.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>330</width>
<height>281</height>
<height>296</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -541,6 +541,29 @@
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_fill">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>fill</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="3" column="1" colspan="3">
<widget class="QCheckBox" name="bool_fill">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_3">
Expand Down
15 changes: 15 additions & 0 deletions glue/viewers/scatter/qt/tests/test_python_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ def setup_method(self, method):
def test_simple(self, tmpdir):
self.assert_same(tmpdir)

def test_simple_nofill(self, tmpdir):
if MATPLOTLIB_LT_20:
pytest.xfail()
self.viewer.state.layers[0].fill = False
self.viewer.state.layers[0].size_scaling = 10
self.assert_same(tmpdir)

def test_simple_visual(self, tmpdir):
self.viewer.state.layers[0].color = 'blue'
self.viewer.state.layers[0].markersize = 30
Expand All @@ -46,6 +53,10 @@ def test_cmap_mode(self, tmpdir):
self.viewer.state.layers[0].alpha = 0.8
self.assert_same(tmpdir)

def test_cmap_mode_nofill(self, tmpdir):
self.viewer.state.layers[0].fill = False
self.test_cmap_mode(tmpdir)

def test_size_mode(self, tmpdir):
self.viewer.state.layers[0].size_mode = 'Linear'
self.viewer.state.layers[0].size_att = self.data.id['d']
Expand All @@ -55,6 +66,10 @@ def test_size_mode(self, tmpdir):
self.viewer.state.layers[0].alpha = 0.7
self.assert_same(tmpdir)

def test_size_mode_nofill(self, tmpdir):
self.viewer.state.layers[0].fill = False
self.test_size_mode(tmpdir)

def test_line(self, tmpdir):
self.viewer.state.layers[0].line_visible = True
self.viewer.state.layers[0].linewidth = 10
Expand Down
1 change: 1 addition & 0 deletions glue/viewers/scatter/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ class ScatterLayerState(MatplotlibLayerState):
size_vmin = DDCProperty(docstring="The lower level for the size mapping")
size_vmax = DDCProperty(docstring="The upper level for the size mapping")
size_scaling = DDCProperty(1, docstring="Relative scaling of the size")
fill = DDCProperty(True, docstring="Whether to fill the markers")

# Density map

Expand Down