holoviz / holoviews

With Holoviews, your data visualizes itself.
https://holoviews.org
BSD 3-Clause "New" or "Revised" License
2.7k stars 404 forks source link

QuadMesh doesn't work in HoloMap and DynamicMap #2264

Closed JouriB closed 6 years ago

JouriB commented 6 years ago

I ran into a problem where QuadMesh in a HoloMap or DynamicMap doesn't work. An example for Holomap is below.

I also noticed that an overlay of a HoloMap containing Image objects (which works by itself) with a QuadMesh gives the same error.

import holoviews as hv
import numpy as np

def Quad(i):
    x = np.linspace(-1,1,5)
    y = np.linspace(-1,1,5)
    x,y = np.meshgrid(x,y)
    z = np.linspace(0,9,16).reshape(4,4)

    return hv.QuadMesh((x,-y,z))

hv.HoloMap({i: Quad(1) for i in range(10)})

Traceback:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
D:\Users\Jouri\Anaconda3\lib\site-packages\IPython\core\formatters.py in __call__(self, obj)
    305                 pass
    306             else:
--> 307                 return printer(obj)
    308             # Finally look for special method names
    309             method = get_real_method(obj, self.print_method)

D:\Users\Jouri\Anaconda3\lib\site-packages\holoviews\ipython\display_hooks.py in pprint_display(obj)
    257     if not ip.display_formatter.formatters['text/plain'].pprint:
    258         return None
--> 259     return display(obj, raw=True)
    260 
    261 

D:\Users\Jouri\Anaconda3\lib\site-packages\holoviews\ipython\display_hooks.py in display(obj, raw, **kwargs)
    243     elif isinstance(obj, (HoloMap, DynamicMap)):
    244         with option_state(obj):
--> 245             html = map_display(obj)
    246     else:
    247         return repr(obj) if raw else IPython.display.display(obj, **kwargs)

D:\Users\Jouri\Anaconda3\lib\site-packages\holoviews\ipython\display_hooks.py in wrapped(element)
    130         try:
    131             html = fn(element,
--> 132                       max_frames=OutputSettings.options['max_frames'])
    133 
    134             # Only want to add to the archive for one display hook...

D:\Users\Jouri\Anaconda3\lib\site-packages\holoviews\ipython\display_hooks.py in map_display(vmap, max_frames)
    198         return None
    199 
--> 200     return render(vmap)
    201 
    202 

D:\Users\Jouri\Anaconda3\lib\site-packages\holoviews\ipython\display_hooks.py in render(obj, **kwargs)
     60     if renderer.fig == 'pdf':
     61         renderer = renderer.instance(fig='png')
---> 62     return renderer.html(obj, **kwargs)
     63 
     64 

D:\Users\Jouri\Anaconda3\lib\site-packages\holoviews\plotting\renderer.py in html(self, obj, fmt, css, comm, **kwargs)
    256         """
    257         plot, fmt =  self._validate(obj, fmt)
--> 258         figdata, _ = self(plot, fmt, **kwargs)
    259         if css is None: css = self.css
    260 

D:\Users\Jouri\Anaconda3\lib\site-packages\holoviews\plotting\mpl\renderer.py in __call__(self, obj, fmt)
     96 
     97         if isinstance(plot, tuple(self.widgets.values())):
---> 98             data = plot()
     99         elif fmt in ['png', 'svg', 'pdf', 'html', 'json']:
    100             with mpl.rc_context(rc=plot.fig_rcparams):

D:\Users\Jouri\Anaconda3\lib\site-packages\holoviews\plotting\widgets\__init__.py in __call__(self)
    137 
    138     def __call__(self):
--> 139         return self.render_html(self._get_data())
    140 
    141 

D:\Users\Jouri\Anaconda3\lib\site-packages\holoviews\plotting\widgets\__init__.py in _get_data(self)
    364 
    365     def _get_data(self):
--> 366         data = super(SelectionWidget, self)._get_data()
    367         widgets, dimensions, init_dim_vals = self.get_widgets()
    368         key_data = {} if self.plot.dynamic else self.get_key_data()

D:\Users\Jouri\Anaconda3\lib\site-packages\holoviews\plotting\widgets\__init__.py in _get_data(self)
    153             json_path = json_path + '/'
    154         dynamic = json.dumps(self.plot.dynamic) if self.plot.dynamic else 'false'
--> 155         return dict(CDN=CDN, frames=self.get_frames(), delay=delay,
    156                     cached=cached, load_json=load_json, mode=mode, id=self.id,
    157                     Nframes=len(self.plot), widget_name=name, json_path=json_path,

D:\Users\Jouri\Anaconda3\lib\site-packages\holoviews\plotting\mpl\widgets.py in get_frames(self)
     34             frames = {0: self.plot.comm._comm_socket.html}
     35         elif self.embed:
---> 36             return super(MPLWidget, self).get_frames()
     37         else:
     38             frames = {0: self._plot_figure(0)}

D:\Users\Jouri\Anaconda3\lib\site-packages\holoviews\plotting\widgets\__init__.py in get_frames(self)
    167         if self.embed:
    168             frames = OrderedDict([(idx, self._plot_figure(idx))
--> 169                                   for idx in range(len(self.plot))])
    170         else:
    171             frames = {}

D:\Users\Jouri\Anaconda3\lib\site-packages\holoviews\plotting\widgets\__init__.py in <listcomp>(.0)
    167         if self.embed:
    168             frames = OrderedDict([(idx, self._plot_figure(idx))
--> 169                                   for idx in range(len(self.plot))])
    170         else:
    171             frames = {}

D:\Users\Jouri\Anaconda3\lib\site-packages\holoviews\plotting\mpl\widgets.py in _plot_figure(self, idx)
     25             else:
     26                 figure_format = self.renderer.fig
---> 27             return self.renderer.html(self.plot, figure_format, comm=False)
     28 
     29 

D:\Users\Jouri\Anaconda3\lib\site-packages\holoviews\plotting\renderer.py in html(self, obj, fmt, css, comm, **kwargs)
    256         """
    257         plot, fmt =  self._validate(obj, fmt)
--> 258         figdata, _ = self(plot, fmt, **kwargs)
    259         if css is None: css = self.css
    260 

D:\Users\Jouri\Anaconda3\lib\site-packages\holoviews\plotting\mpl\renderer.py in __call__(self, obj, fmt)
     99         elif fmt in ['png', 'svg', 'pdf', 'html', 'json']:
    100             with mpl.rc_context(rc=plot.fig_rcparams):
--> 101                 data = self._figure_data(plot, fmt, **({'dpi':self.dpi} if self.dpi else {}))
    102         else:
    103             if sys.version_info[0] == 3 and mpl.__version__[:-2] in ['1.2', '1.3']:

D:\Users\Jouri\Anaconda3\lib\site-packages\holoviews\plotting\mpl\renderer.py in _figure_data(self, plot, fmt, bbox_inches, **kwargs)
    218 
    219         bytes_io = BytesIO()
--> 220         fig.canvas.print_figure(bytes_io, **kw)
    221         data = bytes_io.getvalue()
    222         if fmt == 'svg':

D:\Users\Jouri\Anaconda3\lib\site-packages\matplotlib\backend_bases.py in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, **kwargs)
   2178                     orientation=orientation,
   2179                     dryrun=True,
-> 2180                     **kwargs)
   2181                 renderer = self.figure._cachedRenderer
   2182                 bbox_inches = self.figure.get_tightbbox(renderer)

D:\Users\Jouri\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py in print_png(self, filename_or_obj, *args, **kwargs)
    525 
    526     def print_png(self, filename_or_obj, *args, **kwargs):
--> 527         FigureCanvasAgg.draw(self)
    528         renderer = self.get_renderer()
    529         original_dpi = renderer.dpi

D:\Users\Jouri\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py in draw(self)
    472 
    473         try:
--> 474             self.figure.draw(self.renderer)
    475         finally:
    476             RendererAgg.lock.release()

D:\Users\Jouri\Anaconda3\lib\site-packages\matplotlib\artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
     59     def draw_wrapper(artist, renderer, *args, **kwargs):
     60         before(artist, renderer)
---> 61         draw(artist, renderer, *args, **kwargs)
     62         after(artist, renderer)
     63 

D:\Users\Jouri\Anaconda3\lib\site-packages\matplotlib\figure.py in draw(self, renderer)
   1157         dsu.sort(key=itemgetter(0))
   1158         for zorder, a, func, args in dsu:
-> 1159             func(*args)
   1160 
   1161         renderer.close_group('figure')

D:\Users\Jouri\Anaconda3\lib\site-packages\matplotlib\artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
     59     def draw_wrapper(artist, renderer, *args, **kwargs):
     60         before(artist, renderer)
---> 61         draw(artist, renderer, *args, **kwargs)
     62         after(artist, renderer)
     63 

D:\Users\Jouri\Anaconda3\lib\site-packages\matplotlib\axes\_base.py in draw(self, renderer, inframe)
   2322 
   2323         for zorder, a in dsu:
-> 2324             a.draw(renderer)
   2325 
   2326         renderer.close_group('axes')

D:\Users\Jouri\Anaconda3\lib\site-packages\matplotlib\artist.py in draw_wrapper(artist, renderer, *args, **kwargs)
     59     def draw_wrapper(artist, renderer, *args, **kwargs):
     60         before(artist, renderer)
---> 61         draw(artist, renderer, *args, **kwargs)
     62         after(artist, renderer)
     63 

D:\Users\Jouri\Anaconda3\lib\site-packages\matplotlib\collections.py in draw(self, renderer)
   1845         offsets.shape = (-1, 2)                 # Make it Nx2
   1846 
-> 1847         self.update_scalarmappable()
   1848 
   1849         if not transform.is_affine:

D:\Users\Jouri\Anaconda3\lib\site-packages\matplotlib\collections.py in update_scalarmappable(self)
    707             return
    708         if self._A.ndim > 1:
--> 709             raise ValueError('Collections can only map rank 1 arrays')
    710         if not self.check_update("array"):
    711             return

ValueError: Collections can only map rank 1 arrays
philippjfr commented 6 years ago

Thanks for reporting this @JouriB. QuadMesh support was recently almost completely rewritten and the above example works fine on master. The fix will land in the v1.10 release.

github-actions[bot] commented 2 weeks ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.