Skip to content

Commit

Permalink
Put presets in chromatic order
Browse files Browse the repository at this point in the history
  • Loading branch information
rosteen committed Nov 14, 2023
1 parent b47d9bf commit f8a99b8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
16 changes: 11 additions & 5 deletions jdaviz/configs/default/plugins/plot_options/plot_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,10 +617,11 @@ def apply_RGB_presets(self):
raise ValueError("RGB presets can only be applied if color mode is Monochromatic.")
# Preselected colors we want to use for 5 or less layers
preset_colors = [self.swatches_palette[0][0],
"#0000FF",
"#00FF00",
self.swatches_palette[1][0],
self.swatches_palette[4][1]]
"#00FF00",
"#0000FF",
self.swatches_palette[4][1]
]

# Switch back to this at the end
initial_layer = self.layer_selected
Expand All @@ -639,9 +640,14 @@ def apply_RGB_presets(self):
if n_visible > 2:
default_opacity = 1 / math.log2(n_visible)
# Sample along a colormap if we have too many layers
if n_visible > len(preset_colors):
if n_visible == 2:
preset_colors = [preset_colors[0], preset_colors[3]]
elif n_visible == 3:
preset_colors = [preset_colors[0], preset_colors[2], preset_colors[3]]
elif n_visible > len(preset_colors):
cmap = matplotlib.colormaps['gist_rainbow'].resampled(n_visible)
preset_colors = [matplotlib.colors.to_hex(cmap(i), keep_alpha=True) for i in range(n_visible)]
preset_colors = [matplotlib.colors.to_hex(cmap(i), keep_alpha=True) for
i in range(n_visible)]

for i in range(n_visible):
self.layer_selected = visible_layers[i]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,8 @@ def test_apply_presets(imviz_helper):
arr = np.arange(36).reshape(6, 6)
po = imviz_helper.plugins['Plot Options']

preset_colors = [po._obj.swatches_palette[0][0], "#0000FF", "#00FF00",
po._obj.swatches_palette[1][0],]
preset_colors = [po._obj.swatches_palette[0][0], po._obj.swatches_palette[1][0],
"#00FF00", "#0000FF", po._obj.swatches_palette[4][1]]

# Test applying presets with < 6 layers

Expand Down

0 comments on commit f8a99b8

Please sign in to comment.