MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / test_colorbar_positioning

Function test_colorbar_positioning

lib/matplotlib/tests/test_colorbar.py:164–212  ·  view source on GitHub ↗
(use_gridspec)

Source from the content-addressed store, hash-verified

162 ],
163 remove_text=True, savefig_kwarg={'dpi': 40}, style='mpl20')
164def test_colorbar_positioning(use_gridspec):
165 data = np.arange(1200).reshape(30, 40)
166 levels = [0, 200, 400, 600, 800, 1000, 1200]
167
168 # -------------------
169 plt.figure()
170 plt.contourf(data, levels=levels)
171 plt.colorbar(orientation='horizontal', use_gridspec=use_gridspec)
172
173 locations = ['left', 'right', 'top', 'bottom']
174 plt.figure()
175 for i, location in enumerate(locations):
176 plt.subplot(2, 2, i + 1)
177 plt.contourf(data, levels=levels)
178 plt.colorbar(location=location, use_gridspec=use_gridspec)
179
180 # -------------------
181 plt.figure()
182 # make some other data (random integers)
183 data_2nd = np.array([[2, 3, 2, 3], [1.5, 2, 2, 3], [2, 3, 3, 4]])
184 # make the random data expand to the shape of the main data
185 data_2nd = np.repeat(np.repeat(data_2nd, 10, axis=1), 10, axis=0)
186
187 color_mappable = plt.contourf(data, levels=levels, extend='both')
188 # test extend frac here
189 hatch_mappable = plt.contourf(data_2nd, levels=[1, 2, 3], colors='none',
190 hatches=['/', 'o', '+'], extend='max')
191 plt.contour(hatch_mappable, colors='black')
192
193 plt.colorbar(color_mappable, location='left', label='variable 1',
194 use_gridspec=use_gridspec)
195 plt.colorbar(hatch_mappable, location='right', label='variable 2',
196 use_gridspec=use_gridspec)
197
198 # -------------------
199 plt.figure()
200 ax1 = plt.subplot(211, anchor='NE', aspect='equal')
201 plt.contourf(data, levels=levels)
202 ax2 = plt.subplot(223)
203 plt.contourf(data, levels=levels)
204 ax3 = plt.subplot(224)
205 plt.contourf(data, levels=levels)
206
207 plt.colorbar(ax=[ax2, ax3, ax1], location='right', pad=0.0, shrink=0.5,
208 panchor=False, use_gridspec=use_gridspec)
209 plt.colorbar(ax=[ax2, ax3, ax1], location='left', shrink=0.5,
210 panchor=False, use_gridspec=use_gridspec)
211 plt.colorbar(ax=[ax1], location='bottom', panchor=False,
212 anchor=(0.8, 0.5), shrink=0.6, use_gridspec=use_gridspec)
213
214
215def test_colorbar_single_ax_panchor_false():

Callers

nothing calls this directly

Calls 4

figureMethod · 0.80
contourfMethod · 0.45
colorbarMethod · 0.45
contourMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…