hvplot icon indicating copy to clipboard operation
hvplot copied to clipboard

Geo paths cannot be colorized

Open AlexeyPechnikov opened this issue 1 year ago • 2 comments

It works for 2 point lines only:

df = gpd.GeoDataFrame({'mission': ['A','B']}, geometry=[
        shapely.geometry.LineString([(0,0), (1,0)]),
        shapely.geometry.LineString([(0,0), (1,1)]),
])
df.hvplot(geo=True, c='mission')
image

But it doesn't work for 3+ point lines:

df = gpd.GeoDataFrame({'mission': ['A','B']}, geometry=[
        shapely.geometry.LineString([(0,0), (1,0), (1,1)]),
        shapely.geometry.LineString([(0,0), (1,1), (0,1)]),
])
df.hvplot(geo=True, c='mission')

BokehUserWarning: ColumnDataSource's columns must be of the same length. Current lengths: ('color', 1), ('mission', 4), ('xs', 4), ('ys', 4)
image

Sure, in the real life we have longer than 2 point lines and hvplot is broken for them. That looks totally useless to limit line size to just 2 points. Obviously, there is no limitation in Matplotlib:

df = gpd.GeoDataFrame({'mission': ['A','B']}, geometry=[
        shapely.geometry.LineString([(0,0), (1,0), (1,1)]),
        shapely.geometry.LineString([(0,0), (1,1), (0,1)]),
])
df.plot(cmap='jet')
image

AlexeyPechnikov avatar Jul 24 '22 08:07 AlexeyPechnikov

It works if your remove c='mission' so this has to do with the colorization by another dimension, it's definitely a bug.

That looks totally useless to limit line size to just 2 points.

So there's obviously no limit to 2 points per path.

A potential workaround for you is to directly use GeoViews, which works as expected. It's a good hint that the bug lies in hvPlot's code base.

import geoviews as gv
gv.extension('bokeh')

gv.Path(df).opts(color='mission', show_legend=True)

image

PRs are always welcome :)

maximlt avatar Jul 24 '22 08:07 maximlt

@maximlt Thanks. Actually, I use polygons but it was so weird when their border geometries (lines) cannot be plotted by some reason :)

AlexeyPechnikov avatar Jul 24 '22 09:07 AlexeyPechnikov

After further investigation I believe this may be related to holoviz/holoviews#4862.

To trigger it, simply do: gv.Path(df).opts(color='mission', show_legend=True, tools=['hover'])

This error:

BokehUserWarning: ColumnDataSource's columns must be of the same length. goes away once the Hover tool is disabled.

I can also add that it happens with both Python 3.7/3.8 and LineString/MultiLineString.

prusswan avatar Feb 24 '23 08:02 prusswan

I'm hitting the issue with 0.8.3 and can verify the adding tools=['hover'] in geoviews triggers it. If there any way to disable to hover tool from hvplot as a workaround.

dharhas avatar Apr 15 '23 17:04 dharhas