Matplotlib: Add A Custom Colorbar That Runs From Full Transparent To Full Color (remove Artifacts)
I am trying to add a custom colorbar to my matplotlib figure, that runs from full transparent (white) to full color (mediumpurple). I have come far, but still a few issues. The wa
Solution 1:
Instead of levels onRGBA
, use HSV
with various saturation:
fig, ax = plt.subplots(figsize=(10, 10))
max_val = 4
transparency_ticks = 50
colors = [mpl.colors.hsv_to_rgb((0.83, a/transparency_ticks, 1))
for a in range(transparency_ticks)]
cmap = mpl.colors.ListedColormap(colors)
norm = mpl.colors.Normalize(vmin=0, vmax=max_val)
cax = fig.add_axes([0.8, 0.17, 0.05, 0.5])
mpl.colorbar.ColorbarBase(cax, cmap=cmap, norm=norm, orientation='vertical')
Post a Comment for "Matplotlib: Add A Custom Colorbar That Runs From Full Transparent To Full Color (remove Artifacts)"