8000 Move colorbar label to constructor call in examples. · matplotlib/matplotlib@000c193 · GitHub
[go: up one dir, main page]

Skip to content

Commit 000c193

Browse files
committed
Move colorbar label to constructor call in examples.
1 parent a494587 commit 000c193

File tree

2 files changed

+23
-24
lines changed

2 files changed

+23
-24
lines changed

examples/specialty_plots/leftventricle_bulleye.py

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -149,17 +149,15 @@ def bullseye_plot(ax, data, seg_bold=None, cmap=None, norm=None):
149149
norm = mpl.colors.Normalize(vmin=1, vmax=17)
150150
# Create an empty ScalarMappable to set the colorbar's colormap and norm.
151151
# The following gives a basic continuous colorbar with ticks and labels.
152-
cb1 = fig.colorbar(mpl.cm.ScalarMappable(cmap=cmap, norm=norm),
153-
cax=axl, orientation='horizontal')
154-
cb1.set_label('Some Units')
152+
fig.colorbar(mpl.cm.ScalarMappable(cmap=cmap, norm=norm),
153+
cax=axl, orientation='horizontal', label='Some Units')
155154

156155

157156
# And again for the second colorbar.
158157
cmap2 = mpl.cm.cool
159158
norm2 = mpl.colors.Normalize(vmin=1, vmax=17)
160-
cb2 = fig.colorbar(mpl.cm.ScalarMappable(cmap=cmap2, norm=norm2),
161-
cax=axl2, orientation='horizontal')
162-
cb2.set_label('Some other units')
159+
fig.colorbar(mpl.cm.ScalarMappable(cmap=cmap2, norm=norm2),
160+
cax=axl2, orientation='horizontal', label='Some other units')
163161

164162

165163
# The second example illustrates the use of a ListedColormap, a
@@ -173,15 +171,15 @@ def bullseye_plot(ax, data, seg_bold=None, cmap=None, norm=None):
173171
# monotonically increasing.
174172
bounds = [2, 3, 7, 9, 15]
175173
norm3 = mpl.colors.BoundaryNorm(bounds, cmap3.N)
176-
cb3 = fig.colorbar(mpl.cm.ScalarMappable(cmap=cmap3, norm=norm3),
177-
cax=axl3,
178-
# to use 'extend', you must specify two extra boundaries:
179-
boundaries=[0] + bounds + [18],
180-
extend='both',
181-
ticks=bounds, # optional
182-
spacing='proportional',
183-
orientation='horizontal')
184-
cb3.set_label('Discrete intervals, some other units')
174+
fig.colorbar(mpl.cm.ScalarMappable(cmap=cmap3, norm=norm3),
175+
cax=axl3,
176+
# to use 'extend', you must specify two extra boundaries:
177+
boundaries=[0] + bounds + [18],
178+
extend='both',
179+
ticks=bounds, # optional
180+
spacing='proportional',
181+
orientation='horizontal',
182+
label='Discrete intervals, some other units')
185183

186184

187185
# Create the 17 segment model

tutorials/colors/colorbar_only.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,8 @@
3535
cmap = mpl.cm.cool
3636
norm = mpl.colors.Normalize(vmin=5, vmax=10)
3737

38-
cb1 = fig.colorbar(mpl.cm.ScalarMappable(norm=norm, cmap=cmap),
39-
cax=ax, orientation='horizontal')
40-
cb1.set_label('Some Units')
38+
fig.colorbar(mpl.cm.ScalarMappable(norm=norm, cmap=cmap),
39+
cax=ax, orientation='horizontal', label='Some Units')
4140

4241
###############################################################################
4342
# Discrete intervals colorbar
@@ -70,15 +69,16 @@
7069

7170
bounds = [1, 2, 4, 7, 8]
7271
norm = mpl.colors.BoundaryNorm(bounds, cmap.N)
73-
cb2 = fig.colorbar(
72+
fig.colorbar(
7473
mpl.cm.ScalarMappable(cmap=cmap, norm=norm),
7574
cax=ax,
7675
boundaries=[0] + bounds + [13],
7776
extend='both',
7877
ticks=bounds,
7978
spacing='proportional',
80-
orientation='horizontal')
81-
cb2.set_label('Discrete intervals, some other units')
79+
orientation='horizontal',
80+
label='Discrete intervals, some other units',
81+
)
8282

8383
###############################################################################
8484
# Colorbar with custom extension lengths
@@ -98,15 +98,16 @@
9898

9999
bounds = [-1.0, -0.5, 0.0, 0.5, 1.0]
100100
norm = mpl.colors.BoundaryNorm(bounds, cmap.N)
101-
cb3 = fig.colorbar(
101+
fig.colorbar(
102102
mpl.cm.ScalarMappable(cmap=cmap, norm=norm),
103103
cax=ax,
104104
boundaries=[-10] + bounds + [10],
105105
extend='both',
106106
extendfrac='auto',
107107
ticks=bounds,
108108
spacing='uniform',
109-
orientation='horizontal')
110-
cb3.set_label('Custom extension lengths, some other units')
109+
orientation='horizontal',
110+
label='Custom extension lengths, some other units',
111+
)
111112

112113
plt.show()

0 commit comments

Comments
 (0)
0