コード例 #1
0
def basemap_yticks(ax,
                   ticks,
                   side='left',
                   add=True,
                   fontsize=10,
                   formatter=None):
    """
    Calculate and insert yticks on a GeoAxis

    Parameters
    ----------
    ax : ``GeoAxes``
        GeoAxes that the yticks need to be inserted in
    ticks : list
        locations of the ticks in PlateCarree coordinates
    side : {"left", "right"}
        side of the axes that gets the ticks
    add : bool, optional
        if both bottom and top are different and both need to be added, one (or both) of the calls to this function
        should have 'add' = True
    fontsize : float, optional
        fontsize of the labels
    formatter : matplotlib.tickformatter, optional
        The formatter for the labels. The default is the default cartopy LatitudeFormatter
    """
    # tick_extractor (pick the second coordinate)
    te = lambda xy: xy[1]
    # line_constructor (create line with fixed y-coordinates and variabel x coordinates)
    lc = lambda t, n, b: np.vstack(
        (np.linspace(b[0] - 1, b[1] + 1, n), np.zeros(n) + t)).T
    yticks, yticklabels = _basemap_ticks(ax, ticks, side, lc, te)

    # Insert and format the ticks
    if add:
        ax = _clone_geoaxes(ax)
    ax.tick_params(axis='both', which='both', length=0, labelsize=fontsize)
    if side == "right":
        ax.yaxis.tick_right()

    if isinstance(formatter, type(None)):
        formatter = LatitudeFormatter()

    formatter.set_locs(yticklabels)
    yticklabels_formatted = [formatter(value) for value in yticklabels]

    ax.set_yticks(yticks)
    ax.set_yticklabels(yticklabels_formatted)
コード例 #2
0
ファイル: test_ticker.py プロジェクト: hugovk/cartopy
def test_LatitudeFormatter_minutes_seconds(test_ticks, expected):
    formatter = LatitudeFormatter(dms=True, auto_hide=True)
    formatter.set_locs(test_ticks)
    result = [formatter(tick) for tick in test_ticks]
    assert result == expected
コード例 #3
0
ファイル: test_ticker.py プロジェクト: SciTools/cartopy
def test_LatitudeFormatter_minutes_seconds(test_ticks, expected):
    formatter = LatitudeFormatter(dms=True, auto_hide=True)
    formatter.set_locs(test_ticks)
    result = [formatter(tick) for tick in test_ticks]
    assert result == expected