Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

central_longitude doesn't update lon tick labels #329

Open
ahuang11 opened this issue May 9, 2019 · 2 comments
Open

central_longitude doesn't update lon tick labels #329

ahuang11 opened this issue May 9, 2019 · 2 comments

Comments

@ahuang11
Copy link
Collaborator

ahuang11 commented May 9, 2019

image

import numpy as np
import cartopy.crs as ccrs
import xarray as xr
import hvplot.xarray

def sample_data(shape=(73, 145)):
    """Returns ``lons``, ``lats`` and ``data`` of some fake data."""
    nlats, nlons = shape
    ys = np.linspace(-np.pi / 2, np.pi / 2, nlats)
    xs = np.linspace(0, 2*np.pi, nlons)
    lons, lats = np.meshgrid(xs, ys)
    wave = 0.75 * (np.sin(2 * lats) ** 8) * np.cos(4 * lons)
    mean = 0.5 * np.cos(2 * lats) * ((np.sin(2 * lats)) ** 2 + 2)

    lats = np.rad2deg(ys)
    lons = np.rad2deg(xs)
    data = wave + mean

    return lons, lats, data

lons, lats, data = sample_data()

ds = xr.DataArray(data, coords={'lat': lats, 'lon': lons}, dims=('lat', 'lon'))

ds.hvplot('lon', 'lat', crs=ccrs.PlateCarree()) * gv.feature.coastline()
ds.hvplot('lon', 'lat', crs=ccrs.PlateCarree(), projection=ccrs.PlateCarree(central_longitude=180)) * gv.feature.coastline()
@jorgeperezg
Copy link

This issue is problematic for regional grids crossing the 180th meridian.

Using projection=ccrs.PlateCarree(central_longitude=180) shows wrong longitudes in the labels and when hovering.

Using projection=ccrs.PlateCarree() creates a thin 360 degrees long plot that looks awful.
Adding global_extent=True makes the plot look a bit better but a regional grid looks tiny in a global plot.

Has anyone found a fix or a workaround for this?

@ahuang11
Copy link
Collaborator Author

ahuang11 commented Oct 5, 2023

You could likely overwrite the ticks manually by zipping through the bad ticks with the correct ticks labels

import numpy as np
import cartopy.crs as ccrs
import xarray as xr
import geoviews as gv
import hvplot.xarray

def sample_data(shape=(73, 145)):
    """Returns ``lons``, ``lats`` and ``data`` of some fake data."""
    nlats, nlons = shape
    ys = np.linspace(-np.pi / 2, np.pi / 2, nlats)
    xs = np.linspace(0, 2*np.pi, nlons)
    lons, lats = np.meshgrid(xs, ys)
    wave = 0.75 * (np.sin(2 * lats) ** 8) * np.cos(4 * lons)
    mean = 0.5 * np.cos(2 * lats) * ((np.sin(2 * lats)) ** 2 + 2)

    lats = np.rad2deg(ys)
    lons = np.rad2deg(xs)
    data = wave + mean

    return lons, lats, data

lons, lats, data = sample_data()

ds = xr.DataArray(data, coords={'lat': lats, 'lon': lons}, dims=('lat', 'lon'))

# ds.hvplot('lon', 'lat', crs=ccrs.PlateCarree()) * gv.feature.coastline()
ds.hvplot('lon', 'lat', crs=ccrs.PlateCarree(), projection=ccrs.PlateCarree(central_longitude=180)).opts(xticks=[(0, "New Tick")]) * gv.feature.coastline()
image

@ahuang11 ahuang11 self-assigned this May 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants