def test_LongitudeFormatter_minutes_seconds_direction_label(test_ticks, expected): formatter = LongitudeFormatter( dms=True, auto_hide=True, direction_label=False) formatter.set_locs(test_ticks) result = [formatter(tick) for tick in test_ticks] assert result == expected
def test_LongitudeFormatter_minutes_seconds(test_ticks, direction_label, expected): formatter = LongitudeFormatter(dms=True, auto_hide=True, direction_label=direction_label) formatter.set_locs(test_ticks) result = [formatter(tick) for tick in test_ticks] prefix = '' if direction_label else '-' suffix = 'W' if direction_label else '' expected = [ f'{prefix}{text[:-1]}{suffix}' if text[-1] == 'W' else text for text in expected ] assert result == expected
def basemap_xticks(ax, ticks, side='bottom', add=True, fontsize=10, formatter=None): """ Calculate and insert xticks on a GeoAxis Parameters ---------- ax : ``GeoAxes`` GeoAxes that the xticks need to be inserted in ticks : list locations of the ticks in PlateCarree coordinates side : {"top", "bottom"} 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 LongitudeFormatter """ # tick_extractor (pick the first coordinate) te = lambda xy: xy[0] # line_constructor (create line with fixed x-coordinates and variabel y coordinates) lc = lambda t, n, b: np.vstack( (np.zeros(n) + t, np.linspace(b[2] - 1, b[3] + 1, n))).T xticks, xticklabels = _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 == "top": ax.xaxis.tick_top() if isinstance(formatter, type(None)): formatter = LongitudeFormatter() formatter.set_locs(xticklabels) xticklabels_formatted = [formatter(value) for value in xticklabels] ax.set_xticks(xticks) ax.set_xticklabels(xticklabels_formatted)
def test_LongitudeFormatter_minutes_seconds(test_ticks, expected): formatter = LongitudeFormatter(dms=True, auto_hide=True) formatter.set_locs(test_ticks) result = [formatter(tick) for tick in test_ticks] assert result == expected