Skip to content

Compability with DataArray.plot() #314

@zxdawn

Description

@zxdawn

Description

The colorbar location can be changed in DataArray.plot().

Steps to reproduce

import xarray as xr
import proplot as pplt

airtemps = xr.tutorial.open_dataset('air_temperature')

air = airtemps.air - 273.15
air2d = air.isel(time=500)

fig, axs = pplt.subplots()
air2d.plot(ax=axs, cbar_kwargs=dict(orientation='horizontal', label='Temperature ($^{\circ}$C)'))

Error:

~/miniconda3/lib/python3.9/site-packages/matplotlib/axis.py in set_label_position(self, position)
   2065         position : {'top', 'bottom'}
   2066         """
-> 2067         self.label.set_verticalalignment(_api.check_getitem({
   2068             'top': 'baseline', 'bottom': 'top',
   2069         }, position=position))

~/miniconda3/lib/python3.9/site-packages/matplotlib/_api/__init__.py in check_getitem(_mapping, **kwargs)
    186         return mapping[v]
    187     except KeyError:
--> 188         raise ValueError(
    189             "{!r} is not a valid value for {}; supported values are {}"
    190             .format(v, k, ', '.join(map(repr, mapping)))) from None

ValueError: 'right' is not a valid value for position; supported values are 'top', 'bottom'

If I set the loc in .plot():

air2d.plot(ax=axs, cbar_kwargs=dict(loc='bottom', label='Temperature ($^{\circ}$C)'))

It doesn't work.
image

Expected behavior: [What you expected to happen]

Control the colorbar using orientation or 'loc'

Equivalent steps in matplotlib

import xarray as xr

airtemps = xr.tutorial.open_dataset('air_temperature')

air = airtemps.air - 273.15
air2d = air.isel(time=500)
air2d.plot(cbar_kwargs=dict(orientation='horizontal',
           pad=0.15, shrink=1, label='Temperature ($^{\circ}$C)'))

image

Proplot version

Paste the results of import matplotlib; print(matplotlib.__version__); import proplot; print(proplot.version)here.

3.5.0
0.9.5.post105

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions