File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ '''
2+ Make a colorbar as a separate figure.
3+ '''
4+
5+ import pylab
6+ import matplotlib as mpl
7+
8+ # Make a figure and axes with dimensions as desired.
9+ fig = pylab .figure (figsize = (8 ,1.5 ))
10+ ax = fig .add_axes ([0.05 , 0.4 , 0.9 , 0.5 ])
11+
12+ # Set the colormap and norm to correspond to the data for which
13+ # the colorbar will be used.
14+ cmap = mpl .cm .cool
15+ norm = mpl .colors .Normalize (vmin = 5 , vmax = 10 )
16+
17+ # ColorbarBase derives from ScalarMappable and puts a colorbar
18+ # in a specified axes, so it has everything needed for a
19+ # standalone colorbar. There are many more kwargs, but the
20+ # following gives a basic continuous colorbar with ticks
21+ # and labels.
22+ cb = mpl .colorbar .ColorbarBase (ax , cmap = cmap ,
23+ norm = norm ,
24+ orientation = 'horizontal' )
25+ cb .set_label ('Some Units' )
26+
27+ pylab .show ()
28+
You can’t perform that action at this time.
0 commit comments