Plot polylines with dynamic colormap

I am trying to plot polylines with datashader and geoviews. Below is the code snippet:

path = gv.Path(polylineslist)
plot = geomap * datashade(path, cmap=["red"], width=5)
plot.opts(width=900, height=600)

This plots lines with red color. I would like to plot these lines with dynamic color based on some calculations on the property value of the lines.
Could someone please help?

2 Likes

What property value of the lines? Do you mean a categorical value? In that case have a look at the “Multidimensional Plots” section of the Large data user guide, i.e. use count_cat to refer to that column and provide a color_key. If you want something else you’ll have to be more specific.

,geometry,total_num,color
0,"MULTILINESTRING ((13.34929 52.45899, 13.34926 52.45915))",2,#ffec00
1,"MULTILINESTRING ((13.32781 52.42269, 13.3293 52.42307))",7,#ffc900
2,"MULTILINESTRING ((13.34553 52.46091, 13.34538 52.46104, 13.34523 52.46116, 13.34508 52.46128, 13.345 52.46133))",88,#ff8100
3,"MULTILINESTRING ((13.31257 52.46296, 13.31311 52.46356))",18,#ffae00
4,"MULTILINESTRING ((13.33764 52.45941, 13.33765 52.46027))",7,#ffc900
5,"MULTILINESTRING ((13.3401 52.44393, 13.33999 52.44401, 13.33992 52.44405, 13.33988 52.44406, 13.3397 52.44413, 13.33951 52.4442, 13.3393 52.44428, 13.33902 52.44437))",258,#ff6300

The sample data is as shown above. I wish to visualize this data on a map using geoviews and the color of the line string should be the value from color column. Currently, I have calculated the color value using the code snippet:

color_value = math.log2( max(total_num, 0.1) )
c = colormap(color_value)

Also, not sure if it’s possible to show the data for total_num on hover of the linestring.
Could you please help?

Update: I tried plotting this with geoviews and was able to plot with the below snippet:

paths = gv.Path(gdf, vdims=['total_num', 'color']).opts(opts.Path(tools=['hover'], color='color'))

Now, I am facing an issue with scaling this solution? It is able to plot quickly for a few records (around 100-200). But, fails to plot records around 30K?
Any solution would be quite helpful

Although the length of all the columns are same, this leads to warning:

BokehUserWarning: ColumnDataSource's columns must be of the same length. Current lengths: ('color', 99), ('total_num_of_messages', 195), ('xs', 195), ('ys', 195)

Update: This issue occurs because we have MultiLineString with multiple points and the 99 records are expanded to ColumnDataSource’s 195 records, but color is a single value.
Please help

1 Like