8000 Call for new figure in each rst block · matplotlib/matplotlib@6ae3c6f · GitHub
[go: up one dir, main page]

Skip to content

Commit 6ae3c6f

Browse files
committed
Call for new figure in each rst block
1 parent 3c19954 commit 6ae3c6f

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

tutorials/colors/colorbar_only.py

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,31 +16,31 @@
1616
colorbar.
1717
1818
We will start by making a figure of desired size and adding three axes.
19+
20+
Basic continuous colorbar
21+
-------------------------
22+
23+
Set the colormap and norm to correspond to the data for which the colorbar
24+
will be used. Then create the colorbar by calling
25+
:class:`~matplotlib.colorbar.ColorbarBase` and specify axis, colormap, norm
26+
and orientation as parameters. Here we create a basic continuous colorbar
27+
with ticks and labels. More information on colorbar api can be found
28+
`here <https://matplotlib.org/api/colorbar_api.html>`.
1929
"""
2030

2131
import matplotlib.pyplot as plt
2232
import matplotlib as mpl
2333

24-
fig, (ax1, ax2, ax3) = plt.subplots(nrows=3)
25-
26-
###############################################################################
27-
# Basic continuous colorbar
28-
# -------------------------
29-
#
30-
# Set the colormap and norm to correspond to the data for which the colorbar
31-
# will be used. Then create the colorbar by calling
32-
# :class:`~matplotlib.colorbar.ColorbarBase` and specify axis, colormap, norm
33-
# and orientation as parameters. Here we create a basic continuous colorbar
34-
# with ticks and labels. More information on colorbar api can be found
35-
# `here <https://matplotlib.org/api/colorbar_api.html>`.
34+
fig, ax = plt.subplots()
3635

3736
cmap = mpl.cm.cool
3837
norm = mpl.colors.Normalize(vmin=5, vmax=10)
3938

40-
cb1 = mpl.colorbar.ColorbarBase(ax1, cmap=cmap,
39+
cb1 = mpl.colorbar.ColorbarBase(ax, cmap=cmap,
4140
norm=norm,
4241
orientation='horizontal')
4342
cb1.set_label('Some Units')
43+
fig.show()
4444

4545
###############################################################################
4646
# Discrete intervals colorbar
@@ -64,20 +64,23 @@
6464
# *extend*, you must specify two extra boundaries. Finally spacing argument
6565
# ensures that intervals are shown on colorbar proportionally.
6666

67+
fig, ax = plt.subplots()
68+
6769
cmap = mpl.colors.ListedColormap(['red', 'green', 'blue', 'cyan'])
6870
cmap.set_over('0.25')
6971
cmap.set_under('0.75')
7072

7173
bounds = [1, 2, 4, 7, 8]
7274
norm = mpl.colors.BoundaryNorm(bounds, cmap.N)
73-
cb2 = mpl.colorbar.ColorbarBase(ax2, cmap=cmap,
75+
cb2 = mpl.colorbar.ColorbarBase(ax, cmap=cmap,
7476
norm=norm,
7577
boundaries=[0] + bounds + [13],
7678
extend='both',
7779
ticks=bounds,
7880
spacing='proportional',
7981
orientation='horizontal')
8082
cb2.set_label('Discrete intervals, some other units')
83+
fig.show()
8184

8285
###############################################################################
8386
# Colorbar with custom extension lengths
@@ -87,14 +90,16 @@
8790
# colorbar with discrete intervals. To make the length of each extension same
8891
# as the length of the interior colors, use ``extendfrac='auto'``.
8992

93+
fig, ax = plt.subplots()
94+
9095
cmap = mpl.colors.ListedColormap(['royalblue', 'cyan',
9196
'yellow', 'orange'])
9297
cmap.set_over('red')
9398
cmap.set_under('blue')
9499

95100
bounds = [-1.0, -0.5, 0.0, 0.5, 1.0]
96101
norm = mpl.colors.BoundaryNorm(bounds, cmap.N)
97-
cb3 = mpl.colorbar.ColorbarBase(ax3, cmap=cmap,
102+
cb3 = mpl.colorbar.ColorbarBase(ax, cmap=cmap,
98103
norm=norm,
99104
boundaries=[-10] + bounds + [10],
100105
extend='both',
@@ -103,6 +108,4 @@
103108
spacing='uniform',
104109
orientation='horizontal')
105110
cb3.set_label('Custom extension lengths, some other units')
106-
107-
plt.tight_layout()
108-
plt.show()
111+
fig.show()

0 commit comments

Comments
 (0)
0