holoviz / holoviz/hvplot

problem plotting labels with `geo=True`

Open
#596 0 comments 0 reactions 0 assignees View on GitHub
api: geo
Dominant language
Python
Stars
1.4k
Forks
124
Avg merge
1d 18h
Merged PRs (30d)
1

Description

#### ALL software version info
(this library, plus any other relevant software, e.g. bokeh, python, notebook, OS, browser, etc)
hvplot 0.7.1
holoviews 1.14.2
geoviews 1.9.1

#### Description of expected behavior and the observed behavior
This is related to an issue I responded to on [StackOverflow](https://stackoverflow.com/questions/67005004/how-can-i-overlay-text-labels-on-a-geographic-hvplot-points-plot).

I would expect this to work:
```python
gdf.hvplot.labels(text="labels", geo=True)
```

#### Complete, minimal, self-contained example code that reproduces the issue

```
import geopandas as gpd
import pandas as pd
import hvplot.pandas
import geoviews as gv
from geoviews import tile_sources as gvts

raw = """8911 POINT (5.79557 53.20121)
8912 POINT (5.76973 53.18031)
8913 POINT (5.78159 53.20088)
8914 POINT (5.75442 53.20394)
8915 POINT (5.76594 53.21173)"""

data = [(_[0], _[-2], _[-1]) for _ in [_.replace("(", "").replace(")", "").split() for _ in raw.split("\n")]]
df = pd.DataFrame(data, columns=["labels", "x", "y"]).astype({"labels": str})
gdf = gpd.GeoDataFrame(df, geometry=gpd.points_from_xy(df.x, df.y, crs="EPSG:4326"))

tiles = gvts.CartoLight
points = gdf.hvplot(geo=True, tiles="CartoLight")

# This doesn't work, but I would think it should:
labels = gdf.hvplot.labels(text="labels", geo=True)

# This works, but seems like a work-around:
# labels = gdf.to_crs("EPSG:3857").assign(x=lambda df: df.geometry.x, y=lambda df: df.geometry.y).hvplot.labels(text="labels", x="x", y="y")

(points * labels * tiles).opts(height=600, width=800)
```

#### Stack traceback and/or browser JavaScript console output
Below is the error message I encountered, OP encountered a different error.

TypeError: unsupported operand type(s) for /: 'NoneType' and 'NoneType'

'''python
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
~/anaconda3/envs/datum38/lib/python3.8/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:

~/anaconda3/envs/datum38/lib/python3.8/site-packages/holoviews/core/dimension.py in _repr_mimebundle_(self, include, exclude)
1315 combined and returned.
1316 """
-> 1317 return Store.render(self)
1318
1319

~/anaconda3/envs/datum38/lib/python3.8/site-packages/holoviews/core/options.py in render(cls, obj)
1403 data, metadata = {}, {}
1404 for hook in hooks:
-> 1405 ret = hook(obj)
1406 if ret is None:
1407 continue

~/anaconda3/envs/datum38/lib/python3.8/site-packages/holoviews/ipython/display_hooks.py in pprint_display(obj)
280 if not ip.display_formatter.formatters['text/plain'].pprint:
281 return None
--> 282 return display(obj, raw_output=True)
283
284

~/anaconda3/envs/datum38/lib/python3.8/site-packages/holoviews/ipython/display_hooks.py in display(obj, raw_output, **kwargs)
250 elif isinstance(obj, (CompositeOverlay, ViewableElement)):
251 with option_state(obj):
--> 252 output = element_display(obj)
253 elif isinstance(obj, (Layout, NdLayout, AdjointLayout)):
254 with option_state(obj):

~/anaconda3/envs/datum38/lib/python3.8/site-packages/holoviews/ipython/display_hooks.py in wrapped(element)
144 try:
145 max_frames = OutputSettings.options['max_frames']
--> 146 mimebundle = fn(element, max_frames=max_frames)
147 if mimebundle is None:
148 return {}, {}

~/anaconda3/envs/datum38/lib/python3.8/site-packages/holoviews/ipython/display_hooks.py in element_display(element, max_frames)
190 return None
191
--> 192 return render(element)
193
194

~/anaconda3/envs/datum38/lib/python3.8/site-packages/holoviews/ipython/display_hooks.py in render(obj, **kwargs)
66 renderer = renderer.instance(fig='png')
67
---> 68 return renderer.components(obj, **kwargs)
69
70

~/anaconda3/envs/datum38/lib/python3.8/site-packages/holoviews/plotting/renderer.py in components(self, obj, fmt, comm, **kwargs)
408 doc = Document()
409 with config.set(embed=embed):
--> 410 model = plot.layout._render_model(doc, comm)
411 if embed:
412 return render_model(model, comm)

~/anaconda3/envs/datum38/lib/python3.8/site-packages/panel/viewable.py in _render_model(self, doc, comm)
425 if comm is None:
426 comm = state._comm_manager.get_server_comm()
--> 427 model = self.get_root(doc, comm)
428
429 if config.embed:

~/anaconda3/envs/datum38/lib/python3.8/site-packages/panel/viewable.py in get_root(self, doc, comm, preprocess)
482 """
483 doc = init_doc(doc)
--> 484 root = self._get_model(doc, comm=comm)
485 if preprocess:
486 self._preprocess(root)

~/anaconda3/envs/datum38/lib/python3.8/site-packages/panel/layout/base.py in _get_model(self, doc, root, parent, comm)
111 if root is None:
112 root = model
--> 113 objects = self._get_objects(model, [], doc, root, comm)
114 props = dict(self._init_params(), objects=objects)
115 model.update(**self._process_param_change(props))

~/anaconda3/envs/datum38/lib/python3.8/site-packages/panel/layout/base.py in _get_objects(self, model, old_objects, doc, root, comm)
101 else:
102 try:
--> 103 child = pane._get_model(doc, root, model, comm)
104 except RerenderError:
105 return self._get_objects(model, current_objects[:i], doc, root, comm)

~/anaconda3/envs/datum38/lib/python3.8/site-packages/panel/pane/holoviews.py in _get_model(self, doc, root, parent, comm)
237 plot = self.object
238 else:
--> 239 plot = self._render(doc, comm, root)
240
241 plot.pane = self

~/anaconda3/envs/datum38/lib/python3.8/site-packages/panel/pane/holoviews.py in _render(self, doc, comm, root)
302 kwargs['comm'] = comm
303
--> 304 return renderer.get_plot(self.object, **kwargs)
305
306 def _cleanup(self, root):

~/anaconda3/envs/datum38/lib/python3.8/site-packages/holoviews/plotting/bokeh/renderer.py in get_plot(self_or_cls, obj, doc, renderer, **kwargs)
71 combining the bokeh model with another plot.
72 """
---> 73 plot = super(BokehRenderer, self_or_cls).get_plot(obj, doc, renderer, **kwargs)
74 if plot.document is None:
75 plot.document = Document() if self_or_cls.notebook_context else curdoc()

~/anaconda3/envs/datum38/lib/python3.8/site-packages/holoviews/plotting/renderer.py in get_plot(self_or_cls, obj, doc, renderer, comm, **kwargs)
241 init_key = tuple(v if d is None else d for v, d in
242 zip(plot.keys[0], defaults))
--> 243 plot.update(init_key)
244 else:
245 plot = obj

~/anaconda3/envs/datum38/lib/python3.8/site-packages/holoviews/plotting/plot.py in update(self, key)
980 def update(self, key):
981 if len(self) == 1 and ((key == 0) or (key == self.keys[0])) and not self.drawn:
--> 982 return self.initialize_plot()
983 item = self.__getitem__(key)
984 self.traverse(lambda x: setattr(x, '_updated', True))

~/anaconda3/envs/datum38/lib/python3.8/site-packages/holoviews/plotting/bokeh/element.py in initialize_plot(self, ranges, plot, plots, source)
1394 # Initialize plot, source and glyph
1395 if plot is None:
-> 1396 plot = self._init_plot(key, style_element, ranges=ranges, plots=plots)
1397 self._init_axes(plot)
1398 else:

~/anaconda3/envs/datum38/lib/python3.8/site-packages/holoviews/plotting/bokeh/element.py in _init_plot(self, key, element, plots, ranges)
492 subplots = list(self.subplots.values()) if self.subplots else []
493
--> 494 axis_types, labels, plot_ranges = self._axes_props(plots, subplots, element, ranges)
495 xlabel, ylabel, _ = labels
496 x_axis_type, y_axis_type = axis_types

~/anaconda3/envs/datum38/lib/python3.8/site-packages/holoviews/plotting/bokeh/element.py in _axes_props(self, plots, subplots, element, ranges)
403 # Get the Element that determines the range and get_extents
404 range_el = el if self.batched and not isinstance(self, OverlayPlot) else element
--> 405 l, b, r, t = self.get_extents(range_el, ranges)
406 if self.invert_axes:
407 l, b, r, t = b, l, t, r

~/anaconda3/envs/datum38/lib/python3.8/site-packages/holoviews/plotting/plot.py in get_extents(self, element, ranges, range_type, xdim, ydim, zdim)
1451
1452 if self.apply_ranges:
-> 1453 range_extents = self._get_range_extents(element, ranges, range_type, xdim, ydim, zdim)
1454 else:
1455 range_extents = (np.NaN,) * num

~/anaconda3/envs/datum38/lib/python3.8/site-packages/holoviews/plotting/plot.py in _get_range_extents(self, element, ranges, range_type, xdim, ydim, zdim)
1370
1371 mz0, mz1 = get_minimum_span(z0, z1, zspan)
-> 1372 xpad, ypad, zpad = self.get_padding(element, (x0, y0, z0, x1, y1, z1))
1373
1374 if range_type == 'soft':

~/anaconda3/envs/datum38/lib/python3.8/site-packages/holoviews/plotting/plot.py in get_padding(self, obj, extents)
1335 xspan = x1-x0 if util.is_number(x0) and util.is_number(x1) else None
1336 yspan = y1-y0 if util.is_number(y0) and util.is_number(y1) else None
-> 1337 aspect = self.get_aspect(xspan, yspan)
1338 if aspect > 1:
1339 xpad = tuple(xp/aspect for xp in xpad) if isinstance(xpad, tuple) else xpad/aspect

~/anaconda3/envs/datum38/lib/python3.8/site-packages/holoviews/plotting/bokeh/element.py in get_aspect(self, xspan, yspan)
1003 return self.state.frame_width/self.state.frame_height
1004 elif self.data_aspect:
-> 1005 return (yspan/xspan)*self.data_aspect
1006 elif self.aspect == 'equal':
1007 return yspan/xspan

TypeError: unsupported operand type(s) for /: 'NoneType' and 'NoneType'
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.