Skip to content

Instantly share code, notes, and snippets.

@JohannesBuchner
Created April 19, 2023 09:31
Show Gist options
  • Save JohannesBuchner/fad4ece9816f0123fbd61b8d9cc7746f to your computer and use it in GitHub Desktop.
Save JohannesBuchner/fad4ece9816f0123fbd61b8d9cc7746f to your computer and use it in GitHub Desktop.

Revisions

  1. JohannesBuchner created this gist Apr 19, 2023.
    17 changes: 17 additions & 0 deletions colorbar.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    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')