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')