| 162 | ], |
| 163 | remove_text=True, savefig_kwarg={'dpi': 40}, style='mpl20') |
| 164 | def 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 | |
| 215 | def test_colorbar_single_ax_panchor_false(): |