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

Example updates #269

Merged
merged 4 commits into from
Dec 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ jobs:
- source activate test-environment
- doit develop_install $CHANS_DEV -o recommended
- doit env_capture
before-script:
- "echo 'backend : Agg' > $HOME/.matplotlib/matplotlibrc"
script:
- geoviews fetch-data --path=examples
- bokeh sampledata
Expand Down
8 changes: 4 additions & 4 deletions examples/Homepage.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@
"outputs": [],
"source": [
"(gf.ocean + gf.land + gf.ocean * gf.land * gf.coastline * gf.borders).opts(\n",
" 'Feature', projection=crs.Geostationary(), global_extent=True, height=325\n",
").cols(3)"
" 'Feature', projection=crs.Geostationary(), global_extent=True, height=325).cols(3)"
]
},
{
Expand All @@ -52,9 +51,10 @@
"outputs": [],
"source": [
"dataset = gv.Dataset(xr.open_dataset('./data/ensemble.nc'))\n",
"ensemble = dataset.to(gv.Image, ['longitude', 'latitude'])\n",
"ensemble = dataset.to(gv.Image, ['longitude', 'latitude'], 'surface_temperature')\n",
"\n",
"gv.output(ensemble.opts(cmap='viridis', colorbar=True, fig_size=200) * gf.coastline(), backend='matplotlib')"
"gv.output(ensemble.opts(cmap='viridis', colorbar=True, fig_size=200, backend='matplotlib') * gf.coastline(),\n",
" backend='matplotlib')"
]
},
{
Expand Down
13 changes: 8 additions & 5 deletions examples/user_guide/Gridded_Datasets_I.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
"import holoviews as hv\n",
"import geoviews as gv\n",
"import geoviews.feature as gf\n",
"\n",
"from cartopy import crs\n",
"from geoviews import opts\n",
"\n",
"gv.extension('matplotlib')\n",
"\n",
Expand Down Expand Up @@ -190,8 +192,9 @@
"metadata": {},
"outputs": [],
"source": [
"air_temperature = gv.Dataset(xr.open_dataset('../data/pre-industrial.nc'), kdims=['longitude', 'latitude'],\n",
" vdims=['air_temperature'])\n",
"pre_industrial = xr.open_dataset('../data/pre-industrial.nc').load()\n",
"\n",
"air_temperature = gv.Dataset(pre_industrial, ['longitude', 'latitude'], 'air_temperature')\n",
"air_temperature"
]
},
Expand Down Expand Up @@ -225,10 +228,10 @@
"outputs": [],
"source": [
"temp_curve = hv.Curve(xr_dataset.select(longitude=0, latitude=10), kdims=['time'])\n",
"temp_map = xr_dataset.to(gv.Image,['longitude', 'latitude']) * gv.Points([(0,10)], crs=crs.PlateCarree())\n",
"temp_map = xr_dataset.to(gv.Image,['longitude', 'latitude']) * gv.Points([(0,10)])\n",
"(temp_map + temp_curve).opts(\n",
" opts.Curve(aspect=2, xticks=4, xrotation=15),\n",
" opts.Points(color='k'))"
" opts.Points(color='k', global_extent=True))"
]
},
{
Expand Down Expand Up @@ -275,7 +278,7 @@
"srfc_temps = xr_dataset.redim.range(surface_temperature=(300, max_surface_temp)).to(gv.Image,['longitude', 'latitude'])\n",
"\n",
"(srfc_temps * gf.coastline).opts(\n",
" opts.Image(projection=crs.Geostationary(), cmap='Greens', xaxis=None yaxis=None))"
" opts.Image(projection=crs.Geostationary(), cmap='Greens', xaxis=None, yaxis=None))"
]
},
{
Expand Down
46 changes: 27 additions & 19 deletions examples/user_guide/Gridded_Datasets_II.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@
"import holoviews as hv\n",
"import geoviews as gv\n",
"import geoviews.feature as gf\n",
"\n",
"from geoviews import opts\n",
"from cartopy import crs as ccrs\n",
"\n",
"gv.extension('matplotlib', 'bokeh')\n",
"%output size=200"
"\n",
"gv.output(size=200)"
]
},
{
Expand Down Expand Up @@ -56,7 +59,7 @@
"metadata": {},
"outputs": [],
"source": [
"dataset = gv.Dataset(xr_ensembles, vdims='surface_temperature', crs=ccrs.PlateCarree())\n",
"dataset = gv.Dataset(xr_ensembles, vdims='surface_temperature')\n",
"dataset"
]
},
Expand Down Expand Up @@ -114,9 +117,10 @@
"metadata": {},
"outputs": [],
"source": [
"%%opts Points [color_index=2 size_index=None] (cmap='jet')\n",
"hv.Layout([dataset.to(el, geo_dims)[::10, ::5] * gf.coastline\n",
" for el in [gv.FilledContours, gv.LineContours, gv.Points]]).cols(1)"
"layout = hv.Layout([dataset.to(el, geo_dims)[::10, ::5] * gf.coastline\n",
" for el in [gv.FilledContours, gv.LineContours, gv.Points]]).cols(1)\n",
"\n",
"layout.opts(opts.Points(color='surface_temperature', cmap='jet'))"
]
},
{
Expand Down Expand Up @@ -152,10 +156,9 @@
"metadata": {},
"outputs": [],
"source": [
"%%opts QuadMesh [colorbar=True fig_size=300 projection=ccrs.Robinson()] (cmap='RdBu_r')\n",
"xrds = xr.tutorial.load_dataset('rasm')\n",
"qmesh = gv.Dataset(xrds.Tair).to(gv.QuadMesh, ['xc', 'yc'], dynamic=True)\n",
"qmesh.redim.range(Tair=(-30, 30)) * gf.coastline"
"xrds = xr.tutorial.open_dataset('rasm').load()\n",
"qmesh = gv.Dataset(xrds.Tair).to(gv.QuadMesh, ['xc', 'yc'], dynamic=True).redim.range(Tair=(-30, 30))\n",
"qmesh.opts(colorbar=True, cmap='RdBu_r', projection=ccrs.Robinson()) * gf.coastline"
]
},
{
Expand All @@ -173,7 +176,7 @@
"metadata": {},
"outputs": [],
"source": [
"%output backend='bokeh'"
"hv.output(backend='bokeh')"
]
},
{
Expand All @@ -189,8 +192,11 @@
"metadata": {},
"outputs": [],
"source": [
"%%opts Curve [xrotation=25 width=600 height=400] {+framewise} NdOverlay [legend_position='right' toolbar='above']\n",
"dataset.to(hv.Curve, 'time', dynamic=True).overlay('realization')"
"curves = dataset.to(hv.Curve, 'time', dynamic=True).overlay('realization')\n",
"\n",
"curves.opts(\n",
" opts.Curve(xrotation=25, width=600, height=400, framewise=True),\n",
" opts.NdOverlay(legend_position='right', toolbar='right'))"
]
},
{
Expand All @@ -208,8 +214,7 @@
"metadata": {},
"outputs": [],
"source": [
"%%opts HeatMap [width=600 colorbar=True tools=['hover']]\n",
"dataset.to(hv.HeatMap, ['realization', 'time'], dynamic=True)"
"dataset.to(hv.HeatMap, ['realization', 'time'], dynamic=True).opts(width=600, colorbar=True, tools=['hover'])"
]
},
{
Expand All @@ -227,8 +232,9 @@
"metadata": {},
"outputs": [],
"source": [
"%%output backend='matplotlib'\n",
"hv.Layout([dataset.to(hv.Violin, d, groupby=[], datatype=['dataframe']).options(xrotation=25)\n",
"hv.output(backend='matplotlib')\n",
"\n",
"hv.Layout([dataset.to(hv.Violin, d, groupby=[], datatype=['dataframe']).opts(xrotation=25)\n",
" for d in ['time', 'realization']])"
]
},
Expand All @@ -251,7 +257,6 @@
"metadata": {},
"outputs": [],
"source": [
"%%output backend='matplotlib'\n",
"northern = dataset.select(latitude=slice(25, 75))\n",
"(northern.select(longitude=slice(260, 305)).to(gv.Image, geo_dims) *\n",
" northern.select(longitude=slice(330, 362)).to(gv.Image, geo_dims) *\n",
Expand All @@ -273,8 +278,11 @@
"metadata": {},
"outputs": [],
"source": [
"%%opts NdOverlay [width=600 height=400 legend_position='right' toolbar='above'] Curve (color=Palette('Set1'))\n",
"dataset.select(latitude=0, longitude=0).to(hv.Curve, ['time']).reindex().overlay()"
"hv.output(backend='bokeh')\n",
"\n",
"curves = dataset.select(latitude=0, longitude=0).to(hv.Curve, ['time']).reindex().overlay()\n",
"\n",
"curves.opts(width=600, height=400, legend_position='right', toolbar='above')"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion examples/user_guide/Resampling_Grids.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@
"metadata": {},
"outputs": [],
"source": [
"gv.output(quadmeshes.opts(cmap='RdBu_r') * gv.feature.coastline, backend='matplotlib')"
"gv.output(quadmeshes.opts(cmap='RdBu_r') * gv.feature.coastline, backend='matplotlib', size=300)"
]
},
{
Expand Down
6 changes: 3 additions & 3 deletions examples/user_guide/Working_with_Bokeh.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@
"import geoviews.tile_sources as gts\n",
"\n",
"gv.Layout([ts.relabel(name) for name, ts in gts.tile_sources.items()]).opts(\n",
" 'WMTS', xaxis=None, yaxis=None, width=225, height=225\n",
").cols(4)"
" 'WMTS', xaxis=None, yaxis=None, width=225, height=225).cols(4)"
]
},
{
Expand Down Expand Up @@ -187,7 +186,8 @@
"dataset = xr.open_dataset('../data/pre-industrial.nc')\n",
"air_temperature = gv.Dataset(dataset, ['longitude', 'latitude'], 'air_temperature',\n",
" group='Pre-industrial air temperature')\n",
"air_temperature.to.image().opts(tools=['hover'], cmap='viridis') * gf.coastline.options(line_color='black', width=600, height=500)"
"air_temperature.to.image().opts(tools=['hover'], cmap='viridis') *\\\n",
"gf.coastline().opts(line_color='black', width=600, height=500)"
]
}
],
Expand Down
4 changes: 1 addition & 3 deletions geoviews/operation/projection.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ class project_path(_project_operation):
supported_types = [Polygons, Path, Contours, EdgePaths]

def _process_element(self, element):
if element.crs == self.p.projection:
return element
elif not len(element):
if not len(element):
return element.clone(crs=self.p.projection)

crs = element.crs
Expand Down
1 change: 1 addition & 0 deletions geoviews/plotting/bokeh/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ def initialize_plot(self, ranges=None, plot=None, plots=None, source=None):
shape = Shape(self.projection.boundary, crs=self.projection).options(fill_alpha=0)
shapeplot = GeoShapePlot(shape, projection=self.projection,
overlaid=True, renderer=self.renderer)
shapeplot.geographic = False
shapeplot.initialize_plot(plot=fig)
return fig

Expand Down
2 changes: 1 addition & 1 deletion geoviews/plotting/mpl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def _finalize_axis(self, *args, **kwargs):
return ret

def get_data(self, element, ranges, style):
if self._project_operation and self.geographic and element.crs != self.projection:
if self._project_operation and self.geographic:
element = self._project_operation(element, projection=self.projection)
return super(GeoPlot, self).get_data(element, ranges, style)

Expand Down