Skip to content

"_center" postfix on axis label resulting from groupby_bins persists after renaming variable #4322

@lamorton

Description

@lamorton

What happened:

I used groupby_bins + sum to reduce the resolution of my dataset along 'x' dimension. I didn't like the 'x_bins_center' label, so I renamed the x-axis dim/coord to simply 'x.' However, the "_center" postfix is not part of the variable name -- it appears to be some tweaking of the x-axis label when plotting. So now I am stuck with "_center" tagged at the end of the x-axis label, even after the units.

What you expected to happen:

It would make more sense if the '_center' were part of the variable name. That way, the name displayed on the plot is the same one that I need to access the variable in the dataset. Also, when I rename the variable, I will be able to change the way it displays. Furthermore, that will prevent the issue with "_center" getting pasted on after the units.

Minimal Complete Verifiable Example:

import xarray as xr
import numpy as np
data_vars={'y':('x',np.ones((101)),{'units':'kg/m'})}
coords={'x':('x',np.linspace(0,1,101,endpoint=True),{'units':'m'})}
ds = xr.Dataset(data_vars,coords)
dsd = ds.groupby_bins('x',np.linspace(0,1,11,endpoint=True),right=False).sum(dim='x')
dsd.y.plot() #Shows that the x-axis is named "x_bins_center"
dsd = dsd.rename({'x_bins_center':'x'}) #Fails: 
>ValueError: cannot rename 'x_bins_center' because it is not a variable or dimension in this dataset
dsd = dsd.rename({'x_bins':'x'}) #Succeeds, b/c the variable is ACTUALLY named 'x_bins'
dsd.x.attrs['units']='m'
dsd.y.plot() #x-axis label is "x [m]_center"  -- there's a sneaky renaming thing that is appending _center to the end of the label

Anything else we need to know?:

Plots Here's the 1st plot showing the default x-axis label prior to renaming:

Original_plot

Here's the 2nd plot showing the mangled x-axis label after I renamed the variable & reestablished the units:

Butchered_plot

Environment:

Output of xr.show_versions()

INSTALLED VERSIONS

commit: None
python: 3.7.7 (default, Mar 23 2020, 17:31:31)
[Clang 4.0.1 (tags/RELEASE_401/final)]
python-bits: 64
OS: Darwin
OS-release: 19.6.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: en_US.UTF-8
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8
libhdf5: 1.10.4
libnetcdf: 4.6.1

xarray: 0.16.0
pandas: 1.0.3
numpy: 1.18.1
scipy: 1.4.1
netCDF4: 1.4.2
pydap: None
h5netcdf: 0.8.0
h5py: 2.10.0
Nio: None
zarr: None
cftime: 1.2.1
nc_time_axis: None
PseudoNetCDF: None
rasterio: None
cfgrib: None
iris: None
bottleneck: None
dask: 2.20.0
distributed: None
matplotlib: 3.1.3
cartopy: None
seaborn: None
numbagg: None
pint: 0.11
setuptools: 49.2.0.post20200714
pip: 20.1.1
conda: None
pytest: 5.4.1
IPython: 7.13.0
sphinx: 3.1.2

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions