glue icon indicating copy to clipboard operation
glue copied to clipboard

Force line collection to always respect colormap

Open Carifio24 opened this issue 2 years ago • 5 comments

The scatter viewer currently has a bug (noticed by @victoriaono) where the line collection that connects points will only obey the selected colormap if that colormap was set before a line was first displayed on the viewer. Additionally, if a fixed color is set after the line displays, subsequent colormap usage will not be respected. See the video below for an example.

https://user-images.githubusercontent.com/14281631/169670639-f856a81a-ba8b-4c02-ad55-89c1e6b6b8aa.mp4

This PR creates consistent behavior by calling set_color(None) inside the line collection's set_linearcolor method. The reason for this has to do with how the behavior is implemented inside matplotlib. Whenever the colormap mode is Fixed, we call set_linearcolor with color=self.state.color here. This call's the artist's set_color method, which ultimately calls set_facecolor and sets _original_facecolor to that color.

However, when cmap_mode is set to Linear, we call set_mpl_artist_cmap here without a color argument, which doesn't doesn't call set_color, and so _original_facecolor remains as the solid color. The artist's _edge_is_mapped attribute is set to false if _original_edgecolor has a color value, which means that the edgecolors of the artist are set to the original edgecolor, rather than the colormapped colors. This is why things work if we set the colormap before the line first displays - we haven't made a call to the line collection's set_color method yet, so _original_facecolor is still None. By calling set_color(None), we reset _original_facecolor to None, allowing the line collection edges to be colormapped.

Carifio24 avatar May 21 '22 22:05 Carifio24

Codecov Report

Base: 88.09% // Head: 88.06% // Decreases project coverage by -0.03% :warning:

Coverage data is based on head (06374b6) compared to base (a59ef81). Patch has no changes to coverable lines.

:exclamation: Current head 06374b6 differs from pull request most recent head 2d27081. Consider uploading reports for the commit 2d27081 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2299      +/-   ##
==========================================
- Coverage   88.09%   88.06%   -0.04%     
==========================================
  Files         247      247              
  Lines       23563    23476      -87     
==========================================
- Hits        20758    20673      -85     
+ Misses       2805     2803       -2     
Impacted Files Coverage Δ
glue/__init__.py 66.66% <0.00%> (-3.71%) :arrow_down:
glue/core/link_helpers.py 84.61% <0.00%> (-1.28%) :arrow_down:
glue/viewers/matplotlib/qt/widget.py 77.27% <0.00%> (-1.16%) :arrow_down:
glue/core/data.py 91.71% <0.00%> (-0.74%) :arrow_down:
glue/core/layer_artist.py 80.00% <0.00%> (-0.23%) :arrow_down:
glue/core/visual.py 87.38% <0.00%> (-0.23%) :arrow_down:
glue/utils/matplotlib.py 90.27% <0.00%> (-0.21%) :arrow_down:
glue/core/link_manager.py 97.64% <0.00%> (-0.13%) :arrow_down:
glue/core/state.py 91.34% <0.00%> (-0.04%) :arrow_down:
glue/viewers/matplotlib/viewer.py 94.38% <0.00%> (-0.03%) :arrow_down:
... and 7 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

:umbrella: View full report at Codecov.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.

codecov[bot] avatar May 21 '22 23:05 codecov[bot]

Looks good, can you add a changelog entry? (in the 1.6.0 section - you might need to rebase)

astrofrog avatar Aug 04 '22 13:08 astrofrog

@astrofrog I've rebased and added an entry in the changelog

Carifio24 avatar Aug 04 '22 22:08 Carifio24

@Carifio24 - could you rebase this?

astrofrog avatar Aug 05 '22 13:08 astrofrog

@astrofrog I've just rebased

Carifio24 avatar Aug 05 '22 18:08 Carifio24

Just rebasing to resolve a conflict

Carifio24 avatar Oct 13 '22 15:10 Carifio24