|
| 1 | + |
| 2 | +from matplotlib.testing.decorators import image_comparison |
| 3 | +from mpl_toolkits.axes_grid1 import ImageGrid |
| 4 | +import numpy as np |
| 5 | +import matplotlib.pyplot as plt |
| 6 | + |
| 7 | + |
| 8 | +@image_comparison(baseline_images=['imagegrid_cbar_mode'], |
| 9 | + extensions=['png'], |
| 10 | + remove_text=True) |
| 11 | +def test_imagegrid_cbar_mode_edge(): |
| 12 | + X, Y = np.meshgrid(np.linspace(0, 6, 30), np.linspace(0, 6, 30)) |
| 13 | + arr = np.sin(X) * np.cos(Y) + 1j*(np.sin(3*Y) * np.cos(Y/2.)) |
| 14 | + |
| 15 | + fig = plt.figure(figsize=(18, 9)) |
| 16 | + |
| 17 | + positions = (241, 242, 243, 244, 245, 246, 247, 248) |
| 18 | + directions = ['row']*4 + ['column']*4 |
| 19 | + cbar_locations = ['left', 'right', 'top', 'bottom']*2 |
| 20 | + |
| 21 | + for position, direction, location in zip(positions, |
| 22 | + directions, |
| 23 | + cbar_locations): |
| 24 | + grid = ImageGrid(fig, position, |
| 25 | + nrows_ncols=(2, 2), |
| 26 | + direction=direction, |
| 27 | + cbar_location=location, |
| 28 | + cbar_size='20%', |
| 29 | + cbar_mode='edge') |
| 30 | + ax1, ax2, ax3, ax4, = grid |
| 31 | + |
| 32 | + im1 = ax1.imshow(arr.real, cmap='spectral') |
| 33 | + im2 = ax2.imshow(arr.imag, cmap='hot') |
| 34 | + im3 = ax3.imshow(np.abs(arr), cmap='jet') |
| 35 | + im4 = ax4.imshow(np.arctan2(arr.imag, arr.real), cmap='hsv') |
| 36 | + |
| 37 | + # Some of these colorbars will be overridden by later ones, |
| 38 | + # depending on the direction and cbar_location |
| 39 | + ax1.cax.colorbar(im1) |
| 40 | + ax2.cax.colorbar(im2) |
| 41 | + ax3.cax.colorbar(im3) |
| 42 | + ax4.cax.colorbar(im4) |
0 commit comments