Example #1
0
def test_contourf():
    a = np.zeros((4, 5))
    a[0, 0] = -1
    a[1, 1] = 1.1
    a[2, 2] = 2.2
    a[2, 4] = 1.9
    a[3, 3] = 9

    # UL Corner
    g = Grid(nxny=(5, 4),
             dxdy=(1, -1),
             x0y0=(-1, 3),
             proj=wgs84,
             pixel_ref='corner')
    c = Map(g, ny=400, countries=False)

    c.set_cmap(mpl.cm.get_cmap('viridis'))
    c.set_plot_params(levels=[0, 1, 2, 3])
    c.set_data(a)
    s = a * 0.
    s[2, 2] = 1
    c.set_contourf(s,
                   interp='linear',
                   hatches=['xxx'],
                   colors='none',
                   levels=[0.5, 1.5])

    s = a * 0.
    s[0:2, 3:] = 1
    s[0, 4] = 2
    c.set_contour(s,
                  interp='linear',
                  colors='k',
                  linewidths=6,
                  levels=[0.5, 1., 1.5])

    c.set_lonlat_contours(interval=0.5)

    # Add a geometry for fun
    gs = g.to_dict()
    gs['nxny'] = (1, 2)
    gs['x0y0'] = (0, 2)
    gs = Grid.from_dict(gs)
    c.set_geometry(gs.extent_as_polygon(), edgecolor='r', linewidth=2)

    fig, ax = plt.subplots(1)
    c.visualize(ax=ax)
    fig.tight_layout()

    # remove it
    c.set_contourf()
    c.set_contour()

    return fig
Example #2
0
def test_contourf():
    a = np.zeros((4, 5))
    a[0, 0] = -1
    a[1, 1] = 1.1
    a[2, 2] = 2.2
    a[2, 4] = 1.9
    a[3, 3] = 9

    # UL Corner
    g = Grid(nxny=(5, 4),
             dxdy=(1, -1),
             ul_corner=(-1, 3),
             proj=wgs84,
             pixel_ref='corner')
    c = Map(g, ny=400, countries=False)

    c.set_cmap(mpl.cm.get_cmap('viridis'))
    c.set_plot_params(levels=[0, 1, 2, 3])
    c.set_data(a)
    s = a * 0.
    s[2, 2] = 1
    c.set_contourf(s,
                   interp='linear',
                   hatches=['xxx'],
                   colors='none',
                   levels=[0.5, 1.5])

    s = a * 0.
    s[0:2, 3:] = 1
    s[0, 4] = 2
    c.set_contour(s,
                  interp='linear',
                  colors='k',
                  linewidths=6,
                  levels=[0.5, 1., 1.5])

    c.set_lonlat_contours(interval=0.5)

    fig, ax = plt.subplots(1)
    c.visualize(ax=ax)
    fig.tight_layout()

    # remove it
    c.set_contourf()
    c.set_contour()

    return fig
Example #3
0
def test_contourf():
    a = np.zeros((4, 5))
    a[0, 0] = -1
    a[1, 1] = 1.1
    a[2, 2] = 2.2
    a[2, 4] = 1.9
    a[3, 3] = 9

    # UL Corner
    g = Grid(nxny=(5, 4), dxdy=(1, -1), ul_corner=(-1, 3), proj=wgs84,
             pixel_ref='corner')
    c = Map(g, ny=400, countries=False)

    c.set_cmap(mpl.cm.get_cmap('viridis'))
    c.set_plot_params(levels=[0, 1, 2, 3])
    c.set_data(a)
    s = a * 0.
    s[2, 2] = 1
    c.set_contourf(s, interp='linear', hatches=['xxx'], colors='none',
                   levels=[0.5, 1.5])

    s = a * 0.
    s[0:2, 3:] = 1
    s[0, 4] = 2
    c.set_contour(s, interp='linear', colors='k', linewidths=6,
                  levels=[0.5, 1., 1.5])

    c.set_lonlat_contours(interval=0.5)

    fig, ax = plt.subplots(1)
    c.visualize(ax=ax)
    fig.tight_layout()

    # remove it
    c.set_contourf()
    c.set_contour()

    return fig