File: test_axes_grid.py

package info (click to toggle)
matplotlib 2.0.0%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 91,640 kB
  • ctags: 29,525
  • sloc: python: 122,697; cpp: 60,806; ansic: 30,799; objc: 2,830; makefile: 224; sh: 85
file content (42 lines) | stat: -rw-r--r-- 1,605 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42

from matplotlib.testing.decorators import image_comparison
from mpl_toolkits.axes_grid1 import ImageGrid
import numpy as np
import matplotlib.pyplot as plt


@image_comparison(baseline_images=['imagegrid_cbar_mode'],
                  extensions=['png'],
                  remove_text=True)
def test_imagegrid_cbar_mode_edge():
    X, Y = np.meshgrid(np.linspace(0, 6, 30), np.linspace(0, 6, 30))
    arr = np.sin(X) * np.cos(Y) + 1j*(np.sin(3*Y) * np.cos(Y/2.))

    fig = plt.figure(figsize=(18, 9))

    positions = (241, 242, 243, 244, 245, 246, 247, 248)
    directions = ['row']*4 + ['column']*4
    cbar_locations = ['left', 'right', 'top', 'bottom']*2

    for position, direction, location in zip(positions,
                                             directions,
                                             cbar_locations):
        grid = ImageGrid(fig, position,
                         nrows_ncols=(2, 2),
                         direction=direction,
                         cbar_location=location,
                         cbar_size='20%',
                         cbar_mode='edge')
        ax1, ax2, ax3, ax4, = grid

        im1 = ax1.imshow(arr.real, cmap='nipy_spectral')
        im2 = ax2.imshow(arr.imag, cmap='hot')
        im3 = ax3.imshow(np.abs(arr), cmap='jet')
        im4 = ax4.imshow(np.arctan2(arr.imag, arr.real), cmap='hsv')

        # Some of these colorbars will be overridden by later ones,
        # depending on the direction and cbar_location
        ax1.cax.colorbar(im1)
        ax2.cax.colorbar(im2)
        ax3.cax.colorbar(im3)
        ax4.cax.colorbar(im4)