Skip to content

Commit

Permalink
Deal with situation where dmin/dmax cmin/cmax results in 0.0 alpha_cu…
Browse files Browse the repository at this point in the history
…toff
  • Loading branch information
MBARIMike committed Dec 5, 2023
1 parent b4eb9da commit bcb87ff
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions stoqs/tools/colormaps.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ def _plot_color_bar(self, category, cmap, with_alpha=False, file_name=None,
else:
gradient = np.linspace(0, 1, 256)
gradient = np.vstack((gradient, gradient))
if with_alpha:
alpha = np.array([])
if with_alpha and alpha_frac != 0.0:
# First half ramps transparency from full to none
alpha_cutoff = alpha_frac * num_colors
alpha = np.arange(0.0, 1.0, 1.0 / alpha_cutoff).tolist() + int(num_colors - int(alpha_cutoff)) * [1.0]
Expand All @@ -98,18 +99,18 @@ def _plot_color_bar(self, category, cmap, with_alpha=False, file_name=None,
cb_ax.imshow(gradient, aspect='auto', cmap=cm_jetplus)
else:
if category == 'Ocean':
if with_alpha:
if alpha.any():
cb_ax.imshow(gradient, alpha=alpha, aspect='auto', cmap=getattr(cmocean.cm, cmap))
else:
cb_ax.imshow(gradient, aspect='auto', cmap=getattr(cmocean.cm, cmap))
else:
if with_alpha:
if alpha.any():
cb_ax.imshow(gradient, alpha=alpha, aspect='auto', cmap=plt.get_cmap(cmap))
else:
cb_ax.imshow(gradient, aspect='auto', cmap=plt.get_cmap(cmap))

cb_ax.set_axis_off()
if with_alpha:
if alpha.any():
if not file_name:
file_name = os.path.join(str(settings.ROOT_DIR.path('static')), 'images', 'colormaps_alpha', cmap)
cb_fig.savefig(file_name, dpi=100, transparent=True)
Expand Down

0 comments on commit bcb87ff

Please sign in to comment.