hvplot
hvplot copied to clipboard
Geo paths cannot be colorized
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](https://user-images.githubusercontent.com/7342379/180638199-fb732750-4a5c-427f-a678-6ca09a66d872.png)
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](https://user-images.githubusercontent.com/7342379/180638176-b4fb9133-b243-4ab5-a97a-22bb22057948.png)
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](https://user-images.githubusercontent.com/7342379/180638327-d4c9f062-b85a-487d-b530-e9ed199a3187.png)
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)
PRs are always welcome :)
@maximlt Thanks. Actually, I use polygons but it was so weird when their border geometries (lines) cannot be plotted by some reason :)
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.
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.