holoviz-topics / EarthSim

Tools for working with and visualizing environmental simulations.
https://earthsim.holoviz.org
BSD 3-Clause "New" or "Revised" License
65 stars 21 forks source link

Specifying opts.defaults in Analyzing_Meshes #296

Open kcpevey opened 5 years ago

kcpevey commented 5 years ago

I've been trying to set up some default plot options for my project. In my py file I have:

 hv.Store.set_current_backend('bokeh')
 opts.defaults(opts.Points(color='red', size=8, nonselection_alpha=0.5, tools=['hover'], colorbar=True),
               opts.Polygons(color='red', line_width=2, alpha=1.0, selection_alpha=1.0, nonselection_alpha=0.6,
                             selection_color='yellow'),
               opts.Image(colorbar=True))

In my notebooks, I can import my py file and I haven't seen any errors until I try importing this py file as an additional import into Analyzing_Meshes.ipynb. Then, when I get down to visualizing the LineCrossSection:

sector1 = LineCrossSection(trimesh, cb_paths)
sector1.view()

It gives me this error:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
~/miniconda3/envs/env_name/lib/python3.6/site-packages/IPython/core/formatters.py in __call__(self, obj, include, exclude)
    968 
    969             if method is not None:
--> 970                 return method(include=include, exclude=exclude)
    971             return None
    972         else:

~/miniconda3/envs/env_name/lib/python3.6/site-packages/holoviews/core/dimension.py in _repr_mimebundle_(self, include, exclude)
   1398         combined and returned.
   1399         """
-> 1400         return Store.render(self)
   1401 
   1402 

~/miniconda3/envs/env_name/lib/python3.6/site-packages/holoviews/core/options.py in render(cls, obj)
   1451         data, metadata = {}, {}
   1452         for hook in hooks:
-> 1453             ret = hook(obj)
   1454             if ret is None:
   1455                 continue

~/miniconda3/envs/env_name/lib/python3.6/site-packages/holoviews/ipython/display_hooks.py in pprint_display(obj)
    270     if not ip.display_formatter.formatters['text/plain'].pprint:
    271         return None
--> 272     return display(obj, raw_output=True)
    273 
    274 

~/miniconda3/envs/env_name/lib/python3.6/site-packages/holoviews/ipython/display_hooks.py in display(obj, raw_output, **kwargs)
    243     elif isinstance(obj, (Layout, NdLayout, AdjointLayout)):
    244         with option_state(obj):
--> 245             output = layout_display(obj)
    246     elif isinstance(obj, (HoloMap, DynamicMap)):
    247         with option_state(obj):

~/miniconda3/envs/env_name/lib/python3.6/site-packages/holoviews/ipython/display_hooks.py in wrapped(element)
    140         try:
    141             max_frames = OutputSettings.options['max_frames']
--> 142             mimebundle = fn(element, max_frames=max_frames)
    143             if mimebundle is None:
    144                 return {}, {}

~/miniconda3/envs/env_name/lib/python3.6/site-packages/holoviews/ipython/display_hooks.py in layout_display(layout, max_frames)
    213         return None
    214 
--> 215     return render(layout)
    216 
    217 

~/miniconda3/envs/env_name/lib/python3.6/site-packages/holoviews/ipython/display_hooks.py in render(obj, **kwargs)
     63         renderer = renderer.instance(fig='png')
     64 
---> 65     return renderer.components(obj, **kwargs)
     66 
     67 

~/miniconda3/envs/env_name/lib/python3.6/site-packages/holoviews/plotting/bokeh/renderer.py in components(self, obj, fmt, comm, **kwargs)
    247         # Bokeh has to handle comms directly in <0.12.15
    248         comm = False if bokeh_version < '0.12.15' else comm
--> 249         return super(BokehRenderer, self).components(obj,fmt, comm, **kwargs)
    250 
    251 

~/miniconda3/envs/env_name/lib/python3.6/site-packages/holoviews/plotting/renderer.py in components(self, obj, fmt, comm, **kwargs)
    319             plot = obj
    320         else:
--> 321             plot, fmt = self._validate(obj, fmt)
    322 
    323         widget_id = None

~/miniconda3/envs/env_name/lib/python3.6/site-packages/holoviews/plotting/renderer.py in _validate(self, obj, fmt, **kwargs)
    218         if isinstance(obj, tuple(self.widgets.values())):
    219             return obj, 'html'
--> 220         plot = self.get_plot(obj, renderer=self, **kwargs)
    221 
    222         fig_formats = self.mode_formats['fig'][self.mode]

~/miniconda3/envs/env_name/lib/python3.6/site-packages/holoviews/plotting/bokeh/renderer.py in get_plot(self_or_cls, obj, doc, renderer, **kwargs)
    132             curdoc().theme = self_or_cls.theme
    133         doc.theme = self_or_cls.theme
--> 134         plot = super(BokehRenderer, self_or_cls).get_plot(obj, renderer, **kwargs)
    135         plot.document = doc
    136         return plot

~/miniconda3/envs/env_name/lib/python3.6/site-packages/holoviews/plotting/renderer.py in get_plot(self_or_cls, obj, renderer, **kwargs)
    205             init_key = tuple(v if d is None else d for v, d in
    206                              zip(plot.keys[0], defaults))
--> 207             plot.update(init_key)
    208         else:
    209             plot = obj

~/miniconda3/envs/env_name/lib/python3.6/site-packages/holoviews/plotting/plot.py in update(self, key)
    593     def update(self, key):
    594         if len(self) == 1 and ((key == 0) or (key == self.keys[0])) and not self.drawn:
--> 595             return self.initialize_plot()
    596         item = self.__getitem__(key)
    597         self.traverse(lambda x: setattr(x, '_updated', True))

~/miniconda3/envs/env_name/lib/python3.6/site-packages/holoviews/plotting/bokeh/plot.py in initialize_plot(self, plots, ranges)
    950 
    951                 shared_plots = list(passed_plots) if self.shared_axes else None
--> 952                 subplots = subplot.initialize_plot(ranges=ranges, plots=shared_plots)
    953                 nsubplots = len(subplots)
    954 

~/miniconda3/envs/env_name/lib/python3.6/site-packages/holoviews/plotting/bokeh/plot.py in initialize_plot(self, ranges, plots)
   1070             else:
   1071                 passed_plots = plots + adjoined_plots
-> 1072                 adjoined_plots.append(subplot.initialize_plot(ranges=ranges, plots=passed_plots))
   1073         self.drawn = True
   1074         if not adjoined_plots: adjoined_plots = [None]

~/miniconda3/envs/env_name/lib/python3.6/site-packages/geoviews/plotting/bokeh/plot.py in initialize_plot(self, ranges, plot, plots, source)
     86     def initialize_plot(self, ranges=None, plot=None, plots=None, source=None):
     87         opts = {} if isinstance(self, HvOverlayPlot) else {'source': source}
---> 88         fig = super(GeoPlot, self).initialize_plot(ranges, plot, plots, **opts)
     89         if self.geographic and self.show_bounds and not self.overlaid:
     90             from . import GeoShapePlot

~/miniconda3/envs/env_name/lib/python3.6/site-packages/holoviews/plotting/bokeh/element.py in initialize_plot(self, ranges, plot, plots)
   1868                     title = get_tab_title(key, frame, self.hmap.last)
   1869                 panels.append(Panel(child=child, title=title))
-> 1870             self._merge_tools(subplot)
   1871 
   1872         if self.tabs:

~/miniconda3/envs/env_name/lib/python3.6/site-packages/holoviews/plotting/bokeh/element.py in _merge_tools(self, subplot)
   1797             # Datetime formatter may have been applied, remove _dt_strings
   1798             # to match on the hover tooltips, then merge tool renderers
-> 1799             if hover.tooltips and not isinstance(hover.tooltips, util.basestring):
   1800                 tooltips = tuple((name, spec.replace('_dt_strings', ''))
   1801                                   for name, spec in hover.tooltips)

AttributeError: 'NoneType' object has no attribute 'tooltips'

I can remove my default opts from the py file and it works fine. I must be specifying something incorrectly in the defaults, but I'm not sure what its hitting on. Its also confusing that these defaults haven't caused errors in other notebooks. Any ideas on debugging this? The error message is not helpful.

philippjfr commented 5 years ago

Looks like some weird interaction between tools and therefore a bug in holoviews.

kcpevey commented 3 years ago

This should be tested and if valid, moved to holoviews.