Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9a8a48b

Browse files
committed
Added example of a standalone colorbar.
svn path=/trunk/matplotlib/; revision=3769
1 parent b74c08b commit 9a8a48b

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

examples/colorbar_only.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+

0 commit comments

Comments
 (0)