Skip to content

Commit f254b3b

Browse files
authored
Merge pull request #10835 from efiring/colorbar_only_fix_shape
DOC: Make colorbar tutorial examples look like colorbars.
2 parents 6169fa2 + 72f8295 commit f254b3b

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

tutorials/colors/colorbar_only.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
1111
:class:`~matplotlib.colorbar.ColorbarBase` derives from
1212
:mod:`~matplotlib.cm.ScalarMappable` and puts a colorbar in a specified axes,
13-
so it has everything needed for a standalone colorbar. It can be used as is to
14-
make a colorbar for a given colormap and does not need a mappable object like
13+
so it has everything needed for a standalone colorbar. It can be used as-is to
14+
make a colorbar for a given colormap; it does not need a mappable object like
1515
an image. In this tutorial we will explore what can be done with standalone
1616
colorbar.
1717
@@ -22,14 +22,15 @@
2222
will be used. Then create the colorbar by calling
2323
:class:`~matplotlib.colorbar.ColorbarBase` and specify axis, colormap, norm
2424
and orientation as parameters. Here we create a basic continuous colorbar
25-
with ticks and labels. More information on colorbar api can be found
26-
`here <https://matplotlib.org/api/colorbar_api.html>`.
25+
with ticks and labels. More information on the colorbar API can be found
26+
`here <https://matplotlib.org/api/colorbar_api.html>`_.
2727
"""
2828

2929
import matplotlib.pyplot as plt
3030
import matplotlib as mpl
3131

32-
fig, ax = plt.subplots()
32+
fig, ax = plt.subplots(figsize=(6, 1))
33+
fig.subplots_adjust(bottom=0.5)
3334

3435
cmap = mpl.cm.cool
3536
norm = mpl.colors.Normalize(vmin=5, vmax=10)
@@ -62,7 +63,8 @@
6263
# *extend*, you must specify two extra boundaries. Finally spacing argument
6364
# ensures that intervals are shown on colorbar proportionally.
6465

65-
fig, ax = plt.subplots()
66+
fig, ax = plt.subplots(figsize=(6, 1))
67+
fig.subplots_adjust(bottom=0.5)
6668

6769
cmap = mpl.colors.ListedColormap(['red', 'green', 'blue', 'cyan'])
6870
cmap.set_over('0.25')
@@ -85,10 +87,11 @@
8587
# --------------------------------------
8688
#
8789
# Here we illustrate the use of custom length colorbar extensions, used on a
88-
# colorbar with discrete intervals. To make the length of each extension same
89-
# as the length of the interior colors, use ``extendfrac='auto'``.
90+
# colorbar with discrete intervals. To make the length of each extension the
91+
# same as the length of the interior colors, use ``extendfrac='auto'``.
9092

91-
fig, ax = plt.subplots()
93+
fig, ax = plt.subplots(figsize=(6, 1))
94+
fig.subplots_adjust(bottom=0.5)
9295

9396
cmap = mpl.colors.ListedColormap(['royalblue', 'cyan',
9497
'yellow', 'orange'])

0 commit comments

Comments
 (0)