home / github / issue_comments

Menu
  • GraphQL API
  • Search all tables

issue_comments: 459888596

This data as json

html_url issue_url id node_id user created_at updated_at author_association body reactions performed_via_github_app issue
https://github.com/pydata/xarray/issues/619#issuecomment-459888596 https://api.github.com/repos/pydata/xarray/issues/619 459888596 MDEyOklzc3VlQ29tbWVudDQ1OTg4ODU5Ng== 2448579 2019-02-01T22:23:19Z 2019-02-01T22:25:23Z MEMBER

Found a solution for 1. This function works really well even when resizing a figure on matplotlib 3.0.2:

``` python def make_colorbar(ax, mappable, **kwargs): from mpl_toolkits.axes_grid1 import make_axes_locatable import matplotlib as mpl

divider = make_axes_locatable(ax)
orientation = kwargs.pop('orientation', 'vertical')
if orientation == 'vertical':
    loc = 'right'
elif orientation == 'horizontal':
    loc = 'bottom'

cax = divider.append_axes(loc, '5%', pad='3%', axes_class=mpl.pyplot.Axes)
ax.get_figure().colorbar(mappable, cax=cax, orientation=orientation)

```

```python import cartopy.crs as ccrs import xarray as xr

ds = xr.tutorial.open_dataset('air_temperature').load()

ax = plt.subplot(projection=ccrs.LambertConformal()) mappable = ds.air.isel(time=0).plot(transform=ccrs.PlateCarree(), add_colorbar=False) ax.coastlines() ax.gridlines()

make_colorbar(ax, mappable, orientation='vertical') ```

``` python ds = xr.tutorial.open_dataset('air_temperature').load()

ax = plt.subplot(projection=ccrs.LambertConformal()) mappable = ds.air.isel(time=0).plot(transform=ccrs.PlateCarree(), add_colorbar=False) ax.coastlines() ax.gridlines()

make_colorbar(ax, mappable, orientation='horizontal') ```

{
    "total_count": 1,
    "+1": 1,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  110807626
Powered by Datasette · Queries took 0.394ms · About: xarray-datasette