Skip to content

Commit

Permalink
Merge pull request #65 from ioam/various_fixes
Browse files Browse the repository at this point in the history
Various fixes
  • Loading branch information
philippjfr committed Apr 25, 2017
2 parents 6d1eea6 + c77cdd7 commit 6669ed1
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 24 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ many users will want iris and/or xarray as well:


```
conda install -c conda-forge -c ioam holoviews>=1.6.2 geoviews
conda install -c conda-forge -c ioam holoviews geoviews
# (Optional)
conda install xarray
conda install -c conda-forge iris
Expand Down
7 changes: 2 additions & 5 deletions doc/Gridded_Datasets_I.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -318,11 +318,8 @@
"source": [
"%%opts Curve [aspect=2 xticks=4 xrotation=15] Points (color='k')\n",
"temp_curve = hv.Curve(xr_dataset.select(longitude=0, latitude=10), kdims=['time'])\n",
"\n",
"temp_maps = [cb.to(gv.Image,['longitude', 'latitude']) * gv.Points([(0,10)], crs=crs.PlateCarree()) \n",
" for cb in [xr_dataset, air_temperature]]\n",
"\n",
"hv.Layout(temp_maps + [temp_curve]).cols(2)"
"temp_map = xr_dataset.to(gv.Image,['longitude', 'latitude']) * gv.Points([(0,10)], crs=crs.PlateCarree())\n",
"temp_map + temp_curve"
]
},
{
Expand Down
4 changes: 2 additions & 2 deletions doc/Gridded_Datasets_II.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@
"source": [
"## Lower-dimensional views\n",
"\n",
"So far all the conversions shown have incorporated each of the available coordinate dimensions explicitly. However, often times we want to see the spread of values along one or more dimensions, pooling all the other dimensions together. A simple example of this is a box plot where we might want to see the spread of surface_temperature on each day, pooled across all latitude and longitude coordinates. To pool across particular dimensions, we can explicitly declare the \"map\" dimensions, which are the key dimensions of the HoloMap container rather than those of the Elements contained in the HoloMap. By declaring an empty list of ``mdims``, we can tell the conversion interface to pool across all dimensions *except* the particular key dimension(s) supplied, in this case the `'time'` (plot **A**) and `'realization'` (plot **B**):"
"So far all the conversions shown have incorporated each of the available coordinate dimensions explicitly. However, often times we want to see the spread of values along one or more dimensions, pooling all the other dimensions together. A simple example of this is a box plot where we might want to see the spread of surface_temperature on each day, pooled across all latitude and longitude coordinates. To pool across particular dimensions, we can explicitly declare the \"map\" dimensions, which are the key dimensions of the HoloMap container rather than those of the Elements contained in the HoloMap. By explicitly declaring no dimensions to ``groupby``, we can tell the conversion interface to pool across all dimensions *except* the particular key dimension(s) supplied, in this case the `'time'` (plot **A**) and `'realization'` (plot **B**):"
]
},
{
Expand All @@ -220,7 +220,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"This approach also gives us access to other statistical plot types. For instance, with the ``seaborn`` library installed, we can use the ``Distribution`` Element, which visualizes the data as a kernel density estimate. In this way we can visualize how the distribution of surface temperature values varies over time and the model realizations. We do this by omitting 'latitude' and 'longitude' from the list of mdims, generating a lower-dimensional view into the data, where a temperature histogram is shown for every `'realization'` and `'time'`, using `GridSpace`:"
"This approach also gives us access to other statistical plot types. For instance, with the ``seaborn`` library installed, we can use the ``Distribution`` Element, which visualizes the data as a kernel density estimate. In this way we can visualize how the distribution of surface temperature values varies over time and the model realizations. We do this by omitting 'latitude' and 'longitude' from the list of dimensions, generating a lower-dimensional view into the data, where a temperature histogram is shown for every `'realization'` and `'time'`, using `GridSpace`:"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion doc/Projections.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
"outputs": [],
"source": [
"hv.Layout([gf.coastline.relabel(group=p.__name__)(plot=dict(projection=p()))\n",
" for p in projections]).display('all')"
" for p in projections])"
]
},
{
Expand Down
8 changes: 4 additions & 4 deletions doc/Working_with_Bokeh.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@
},
"outputs": [],
"source": [
"%%opts Overlay [width=600 height=300 xaxis=None yaxis=None] \n",
"%%opts Points (size=0.005 cmap='viridis') [tools=['hover'] size_index=2 color_index=2]\n",
"%%opts Overlay [width=600 height=300] \n",
"%%opts Points (size=0.005 cmap='viridis') [tools=['hover'] size_index=2 color_index=2 xaxis=None yaxis=None]\n",
"(gv.WMTS(tiles['Wikipedia']) *\\\n",
"population.to(gv.Points, kdims=['Longitude', 'Latitude'],\n",
" vdims=['Population', 'City', 'Country'], crs=ccrs.PlateCarree()))"
Expand Down Expand Up @@ -181,9 +181,9 @@
},
"outputs": [],
"source": [
"%%opts Shape (cmap='viridis') [xaxis=None yaxis=None tools=['hover'] width=400 height=500 colorbar=True]\n",
"%%opts Shape (cmap='viridis') [tools=['hover'] width=450 height=600 colorbar=True toolbar='above' xaxis=None yaxis=None]\n",
"gv.Shape.from_records(shapes.records(), referendum, on='code', value='leaveVoteshare',\n",
" index='name', crs=ccrs.PlateCarree(), group='EU Referendum')"
" index='name', crs=ccrs.PlateCarree(), group='EU Referendum')"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion geoviews/element/geo.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def __init__(self, data, **kwargs):

def clone(self, data=None, shared_data=True, new_type=None,
*args, **overrides):
if 'crs' not in overrides and isinstance(new_type, _Element):
if 'crs' not in overrides and (not new_type or isinstance(new_type, _Element)):
overrides['crs'] = self.crs
return super(_Element, self).clone(data, shared_data, new_type,
*args, **overrides)
Expand Down
26 changes: 20 additions & 6 deletions geoviews/plotting/bokeh/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@
from bokeh.models import WMTSTileSource
from bokeh.models.tools import BoxZoomTool

from holoviews import Store
from holoviews import Store, Overlay, NdOverlay
from holoviews.core import util
from holoviews.core.options import SkipRendering, Options
from holoviews.plotting.bokeh.annotation import TextPlot
from holoviews.plotting.bokeh.element import ElementPlot
from holoviews.plotting.bokeh.element import ElementPlot, OverlayPlot as HvOverlayPlot
from holoviews.plotting.bokeh.chart import PointPlot
from holoviews.plotting.bokeh.path import PolygonPlot, PathPlot
from holoviews.plotting.bokeh.raster import RasterPlot

from ...element import (WMTS, Points, Polygons, Path, Shape, Image,
Feature, is_geographic, Text)
Feature, is_geographic, Text, _Element)
from ...operation import project_image
from ...util import project_extents, geom_to_array

Expand All @@ -37,7 +37,8 @@ class GeoPlot(ElementPlot):
BoxZoomTool(match_aspect=True), 'reset'],
doc="A list of plugin tools to use on the plot.")

show_grid = param.Boolean(default=False)
show_grid = param.Boolean(default=True, doc="""
Whether to show a gridlines on the plot.""")

def __init__(self, element, **params):
super(GeoPlot, self).__init__(element, **params)
Expand All @@ -62,6 +63,18 @@ def get_extents(self, element, ranges):
return (np.NaN,)*4 if not extents else extents


class OverlayPlot(HvOverlayPlot):
"""
Subclasses the HoloViews OverlayPlot to add custom behavior
for geographic plots.
"""

def __init__(self, element, **params):
self.geographic = any(element.traverse(is_geographic, [_Element]))
if self.geographic:
self.show_grid = False
super(OverlayPlot, self).__init__(element, **params)


class TilePlot(GeoPlot):

Expand Down Expand Up @@ -229,7 +242,9 @@ def get_extents(self, element, ranges=None):
Shape: GeoShapePlot,
Image: GeoRasterPlot,
Feature: FeaturePlot,
Text: GeoTextPlot}, 'bokeh')
Text: GeoTextPlot,
Overlay: OverlayPlot,
NdOverlay: OverlayPlot}, 'bokeh')

options = Store.options(backend='bokeh')

Expand All @@ -242,4 +257,3 @@ def get_extents(self, element, ranges=None):
options.Feature.Lakes = Options('style', fill_color='#97b6e1', line_color='#97b6e1')
options.Feature.Rivers = Options('style', line_color='#97b6e1')
options.Shape = Options('style', line_color='black', fill_color='#30A2DA')

5 changes: 1 addition & 4 deletions geoviews/plotting/mpl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,7 @@ def update_handles(self, *args):
"""
Update the elements of the plot.
"""
if self.geographic:
return GeoPlot.update_handles(self, *args)
else:
return super(GeoImagePlot, self).update_handles(*args)
return GeoPlot.update_handles(self, *args)


class GeoPointPlot(GeoPlot, PointPlot):
Expand Down

0 comments on commit 6669ed1

Please sign in to comment.