Created
April 19, 2023 09:31
-
-
Save JohannesBuchner/fad4ece9816f0123fbd61b8d9cc7746f to your computer and use it in GitHub Desktop.
Manual colorbar with range, shown as a small inset with label
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import matplotlib as mpl | |
import matplotlib.pyplot as plt | |
# make a colormap that can be used to look up colors | |
norm = mpl.colors.Normalize(vmin=0, vmax=3) | |
zcmap = plt.cm.ScalarMappable(norm=norm, cmap=plt.cm.viridis) | |
# use it to plot stuff | |
plt.errorbar( | |
x=1, xerr=0.1, y=2, yerr=0.2, | |
color=zcmap.to_rgba(redshifts[i]), | |
) | |
# show the color bar in the panel | |
cax = plt.axes([0.85, 0.5, 0.02, 0.2]) # left, bottom, width, height | |
cbar = plt.colorbar(zcmap, orientation="vertical", cax=cax) | |
cbar.set_label('redshift') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment