holoviz / hvplot

A high-level plotting API for pandas, dask, xarray, and networkx built on HoloViews
https://hvplot.holoviz.org
BSD 3-Clause "New" or "Revised" License
1.14k stars 109 forks source link

Geo paths cannot be colorized #792

Open AlexeyPechnikov opened 2 years ago

AlexeyPechnikov commented 2 years ago

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
maximlt commented 2 years ago

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 :)

AlexeyPechnikov commented 2 years ago

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

prusswan commented 1 year ago

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.

dharhas commented 1 year ago

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.

kthyng commented 2 months ago

I'm hitting this in geoviews 1.12.0 once I add in tools=['hover'] like everyone above said.