Search code examples
pythongeopandashvplot

Hvplot on GeoDataFrame of categorized linestrings fails to draw different colors


With hvplot 0.5.2 from conda-forge, I'm trying to plot a GeoPandas GeoDataFrame of lines using a column of categorical values called 'mode'. As you can see from the following screenshot, the column is picked up correctly and the three different values are displayed in the legend. However, all lines are drawn in the same color:

filtered.hvplot(geo=True, tiles='OSM', c='mode', line_width=3)

enter image description here

Am I missing something or is this an issue that I should report on the bug tacker?


Solution

  • This has (now) been filed on the bug tracker and can be tracked here and here. However the issue is likely easy to fix. The problem is that it's using the viridis colormap with 256 steps but since the data is categorical it is assigning only the first 3 steps in the colormap to your categories. An easy fix is to change the colormap to something like:

    filtered.hvplot(geo=True, tiles='OSM', c='mode', line_width=3, cmap='Category10')