Space slice colorbar labels in normalized color coordinates
This commit is contained in:
@@ -153,9 +153,11 @@ def render(data: Slice, *, reference_outline: bool = False, title: str | None =
|
|||||||
# under triangle refinement even with identical scalar norms.
|
# under triangle refinement even with identical scalar norms.
|
||||||
artist = ax.imshow(raster[field], extent=bounds, origin="lower", interpolation="none", norm=norm, cmap=cmap, rasterized=True)
|
artist = ax.imshow(raster[field], extent=bounds, origin="lower", interpolation="none", norm=norm, cmap=cmap, rasterized=True)
|
||||||
bar = figure.colorbar(artist, ax=ax, shrink=.82, label="model field units")
|
bar = figure.colorbar(artist, ax=ax, shrink=.82, label="model field units")
|
||||||
ticks = bar.get_ticks()
|
# Space labels in color coordinates so endpoints never crowd an
|
||||||
ticks = ticks[(ticks >= norm.vmin) & (ticks <= norm.vmax)]
|
# automatic tick. Inverting TwoSlopeNorm retains zero at the center
|
||||||
bar.set_ticks(np.unique(np.r_[norm.vmin, ticks, norm.vmax]))
|
# while labeling both unequal ranges with their actual field values.
|
||||||
|
ticks = norm.inverse(np.linspace(0., 1., 5))
|
||||||
|
bar.set_ticks(ticks, labels=[f"{value:.5g}" for value in ticks])
|
||||||
ax.set_title(f"{name}\nsampled min {values.min():.5g}; max {values.max():.5g}\n{note}", fontsize=10)
|
ax.set_title(f"{name}\nsampled min {values.min():.5g}; max {values.max():.5g}\n{note}", fontsize=10)
|
||||||
else:
|
else:
|
||||||
ax.set_title(name)
|
ax.set_title(name)
|
||||||
|
|||||||
Reference in New Issue
Block a user