Skip to content

Commit

Permalink
Added Contours element and plot
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Oct 24, 2017
1 parent 01d9967 commit 82c4468
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 11 deletions.
3 changes: 2 additions & 1 deletion geoviews/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

from .element import (_Element, Feature, Tiles, # noqa (API import)
WMTS, LineContours, FilledContours, Text, Image,
Points, Path, Polygons, Shape, Dataset, RGB)
Points, Path, Polygons, Shape, Dataset, RGB,
Contours)
from . import data # noqa (API import)
from . import operation # noqa (API import)
from . import plotting # noqa (API import)
Expand Down
3 changes: 2 additions & 1 deletion geoviews/element/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

from .geo import (_Element, Feature, Tiles, is_geographic, # noqa (API import)
WMTS, Points, Image, Text, LineContours, RGB,
FilledContours, Path, Polygons, Shape, Dataset)
FilledContours, Path, Polygons, Shape, Dataset,
Contours)


class GeoConversion(ElementConversion):
Expand Down
16 changes: 15 additions & 1 deletion geoviews/element/geo.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from holoviews.core.util import basestring, pd, max_extents, dimension_range
from holoviews.element import (Text as HvText, Path as HvPath,
Polygons as HvPolygons, Image as HvImage,
RGB as HvRGB)
RGB as HvRGB, Contours as HvContours)

from shapely.geometry.base import BaseGeometry
from shapely.geometry import (MultiLineString, LineString,
Expand Down Expand Up @@ -274,6 +274,20 @@ def geom(self):
return path_to_geom(self)


class Contours(_Element, HvContours):
"""
Contours is a Path Element type that may contain any number of
closed paths with an associated value and a coordinate reference
system.
"""

def geom(self):
"""
Returns Path as a shapely geometry.
"""
return path_to_geom(self)


class Polygons(_Element, HvPolygons):
"""
Polygons is a Path Element type that may contain any number of
Expand Down
4 changes: 2 additions & 2 deletions geoviews/operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from holoviews.operation import ElementOperation

from .element import Image, Shape, Polygons, Path, Points
from .element import Image, Shape, Polygons, Path, Points, Contours
from .util import project_extents, geom_to_array


Expand All @@ -21,7 +21,7 @@ class project_path(ElementOperation):
instantiate=False, doc="""
Projection the shape type is projected to.""")

supported_types = [Polygons, Path]
supported_types = [Polygons, Path, Contours]

def _process_element(self, element):
if element.interface.datatype == 'geodataframe':
Expand Down
12 changes: 9 additions & 3 deletions geoviews/plotting/bokeh/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
from holoviews.plotting.bokeh.annotation import TextPlot
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.path import PolygonPlot, PathPlot, ContourPlot
from holoviews.plotting.bokeh.raster import RasterPlot

from ...element import (WMTS, Points, Polygons, Path, Shape, Image,
from ...element import (WMTS, Points, Polygons, Path, Contours, Shape, Image,
Feature, is_geographic, Text, _Element)
from ...operation import project_image, project_shape, project_points, project_path
from ...util import project_extents, geom_to_array
Expand Down Expand Up @@ -158,6 +158,11 @@ class GeoPolygonPlot(GeoPlot, PolygonPlot):
_project_operation = project_path


class GeoContourPlot(GeoPlot, ContourPlot):

_project_operation = project_path


class GeoPathPlot(GeoPlot, PathPlot):

_project_operation = project_path
Expand All @@ -174,9 +179,9 @@ def get_data(self, element, ranges, style):
data = dict(xs=[xs], ys=[ys])

mapping = dict(self._mapping)
dim = element.vdims[0].name if element.vdims else None
if element.level is not None:
cmap = style.get('palette', style.get('cmap', None))
dim = element.vdims[0].name if element.vdims else None
if cmap and dim:
cdim = element.vdims[0]
dim_name = util.dimension_sanitizer(cdim.name)
Expand Down Expand Up @@ -238,6 +243,7 @@ def get_extents(self, element, ranges=None):
Store.register({WMTS: TilePlot,
Points: GeoPointPlot,
Polygons: GeoPolygonPlot,
Contours: GeoContourPlot,
Path: GeoPathPlot,
Shape: GeoShapePlot,
Image: GeoRasterPlot,
Expand Down
18 changes: 15 additions & 3 deletions geoviews/plotting/mpl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@
AnnotationPlot, TextPlot,
LayoutPlot as HvLayoutPlot,
OverlayPlot as HvOverlayPlot,
PathPlot, PolygonPlot, ImagePlot)
PathPlot, PolygonPlot, ImagePlot,
ContourPlot)
from holoviews.plotting.mpl.util import get_raster_array


from ...element import (Image, Points, Feature, WMTS, Tiles, Text,
LineContours, FilledContours, is_geographic,
Path, Polygons, Shape, RGB)
Path, Polygons, Shape, RGB, Contours)
from ...util import path_to_geom, polygon_to_geom, project_extents, geo_mesh

from ...operation import project_points, project_path
Expand Down Expand Up @@ -303,7 +304,17 @@ def init_artists(self, ax, plot_args, plot_kwargs):

class GeoPathPlot(GeoPlot, PathPlot):
"""
Draws a scatter plot from the data in a Points Element.
Draws a Path plot from a Path Element.
"""

apply_ranges = param.Boolean(default=True)

_project_operation = project_path


class GeoContourPlot(GeoPlot, ContourPlot):
"""
Draws a contour plot from a Contours Element.
"""

apply_ranges = param.Boolean(default=True)
Expand Down Expand Up @@ -476,6 +487,7 @@ def draw_annotation(self, axis, data, crs, opts):
Overlay: OverlayPlot,
Polygons: GeoPolygonPlot,
Path: GeoPathPlot,
Contours: GeoContourPlot,
RGB: GeoRGBPlot,
Shape: GeoShapePlot}, 'matplotlib')

Expand Down

0 comments on commit 82c4468

Please sign in to comment.