Skip to content

Commit

Permalink
Merge df71cba into 3b997dc
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Nov 5, 2018
2 parents 3b997dc + df71cba commit 2906f78
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 26 deletions.
6 changes: 1 addition & 5 deletions holoviews/plotting/bokeh/raster.py
Expand Up @@ -70,7 +70,7 @@ def get_data(self, element, ranges, style):



class RGBPlot(RasterPlot):
class RGBPlot(ElementPlot):

style_opts = ['alpha']
_plot_methods = dict(single='image_rgba')
Expand Down Expand Up @@ -113,10 +113,6 @@ def get_data(self, element, ranges, style):
data = dict(image=[img], x=[l], y=[b], dw=[dw], dh=[dh])
return (data, mapping, style)

def _glyph_properties(self, plot, element, source, ranges, style):
return ElementPlot._glyph_properties(self, plot, element,
source, ranges, style)



class HSVPlot(RGBPlot):
Expand Down
4 changes: 2 additions & 2 deletions holoviews/plotting/mpl/__init__.py
Expand Up @@ -155,8 +155,8 @@ def grid_selector(grid):
False: HeatMapPlot},
True),
Image: RasterPlot,
RGB: RasterPlot,
HSV: RasterPlot,
RGB: RGBPlot,
HSV: RGBPlot,

# Graph Elements
Graph: GraphPlot,
Expand Down
60 changes: 41 additions & 19 deletions holoviews/plotting/mpl/raster.py
Expand Up @@ -5,43 +5,28 @@
from ...core import traversal
from ...core.util import match_spec, max_range, unique_iterator
from ...element.raster import Image, Raster, RGB
from .element import ColorbarPlot, OverlayPlot
from .element import ElementPlot, ColorbarPlot, OverlayPlot
from .plot import MPLPlot, GridPlot, mpl_rc_context
from .util import get_raster_array



class RasterPlot(ColorbarPlot):
class RasterBasePlot(ElementPlot):

aspect = param.Parameter(default='equal', doc="""
Raster elements respect the aspect ratio of the
Images by default but may be set to an explicit
aspect ratio or to 'square'.""")

clipping_colors = param.Dict(default={'NaN': 'transparent'})

colorbar = param.Boolean(default=False, doc="""
Whether to add a colorbar to the plot.""")

show_legend = param.Boolean(default=False, doc="""
Whether to show legend for the plot.""")

situate_axes = param.Boolean(default=True, doc="""
Whether to situate the image relative to other plots. """)

style_opts = ['alpha', 'cmap', 'interpolation', 'visible',
'filterrad', 'clims', 'norm']

_plot_methods = dict(single='imshow')

def __init__(self, *args, **kwargs):
super(RasterPlot, self).__init__(*args, **kwargs)
if self.hmap.type == Raster:
self.invert_yaxis = not self.invert_yaxis


def get_extents(self, element, ranges, range_type='combined'):
extents = super(RasterPlot, self).get_extents(element, ranges, range_type)
extents = super(RasterBasePlot, self).get_extents(element, ranges, range_type)
if self.situate_axes or range_type not in ('combined', 'data'):
return extents
else:
Expand All @@ -50,11 +35,22 @@ def get_extents(self, element, ranges, range_type='combined'):
else:
return element.extents


def _compute_ticks(self, element, ranges):
return None, None


class RasterPlot(RasterBasePlot, ColorbarPlot):

clipping_colors = param.Dict(default={'NaN': 'transparent'})

style_opts = ['alpha', 'cmap', 'interpolation', 'visible',
'filterrad', 'clims', 'norm']

def __init__(self, *args, **kwargs):
super(RasterPlot, self).__init__(*args, **kwargs)
if self.hmap.type == Raster:
self.invert_yaxis = not self.invert_yaxis

def get_data(self, element, ranges, style):
xticks, yticks = self._compute_ticks(element, ranges)

Expand Down Expand Up @@ -98,6 +94,32 @@ def update_handles(self, key, axis, element, ranges, style):



class RGBPlot(RasterBasePlot):

style_opts = ['alpha', 'interpolation', 'visible', 'filterrad']

def get_data(self, element, ranges, style):
xticks, yticks = self._compute_ticks(element, ranges)
data = get_raster_array(element)
l, b, r, t = element.bounds.lbrt()
if self.invert_axes:
data = data[::-1, ::-1]
data = data.transpose([1, 0, 2])
l, b, r, t = b, l, t, r
style['extent'] = [l, r, b, t]
style['origin'] = 'upper'
return [data], style, {'xticks': xticks, 'yticks': yticks}

def update_handles(self, key, axis, element, ranges, style):
im = self.handles['artist']
data, style, axis_kwargs = self.get_data(element, ranges, style)
l, r, b, t = style['extent']
im.set_data(data[0])
im.set_extent((l, r, b, t))
return axis_kwargs



class QuadMeshPlot(ColorbarPlot):

clipping_colors = param.Dict(default={'NaN': 'transparent'})
Expand Down

0 comments on commit 2906f78

Please sign in to comment.