Force line collection to always respect colormap #2299
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
scatter-line-bug-2022-05-21_18.14.18.mp4
This PR creates consistent behavior by calling
set_color(None)inside the line collection'sset_linearcolormethod. The reason for this has to do with how the behavior is implemented insidematplotlib. Whenever the colormap mode is Fixed, we callset_linearcolorwithcolor=self.state.colorhere. This call's the artist'sset_colormethod, which ultimately callsset_facecolorand sets_original_facecolorto that color.However, when
cmap_modeis set toLinear, we callset_mpl_artist_cmaphere without a color argument, which doesn't doesn't callset_color, and so_original_facecolorremains as the solid color. The artist's_edge_is_mappedattribute is set to false if_original_edgecolorhas 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'sset_colormethod yet, so_original_facecoloris stillNone. By callingset_color(None), we reset_original_facecolortoNone, allowing the line collection edges to be colormapped.