Use `color` instead of `by` when possible

Using color is faster (likely vectorized, done in 4s)

import pandas as pd

NETWORKS_URL = "https://mesonet.agron.iastate.edu/sites/networks.php?network=_ALL_&format=csv&nohtml=on"

networks_df = pd.read_csv(NETWORKS_URL)
networks_df.hvplot.scatter("lon", "lat", hover_cols=["stid", "station_name"], color="iem_network", legend=False)

vs using by which is looping through overlays (I think, done in 17.5 s)

import pandas as pd

NETWORKS_URL = "https://mesonet.agron.iastate.edu/sites/networks.php?network=_ALL_&format=csv&nohtml=on"

networks_df = pd.read_csv(NETWORKS_URL)
networks_df.hvplot.scatter("lon", "lat", hover_cols=["stid", "station_name"], by="iem_network", legend=False)

2 Likes

That makes sense however I am not sure why the two codes give slightly different colors

I think color is controlled by cmap while by just cycles through the default overlay colors.

Hi, @ahuang11

In many other plot function of hvplot, only “by” exists and no “color”.
For example, hvplot.line
In this case, the plots using “by” is pretty slow. Is there any plan to add the keyword “color” into all the plot functions?
Thanks,

Not planned. Whats your use case?

Maybe you can try Path
Styling Mapping — HoloViews v1.19.1

Thanks a lot.

I am using Pandas + Panel + hvplot to build dashboard.
The slow plotting using “by” on some functions leads to the significant lag of dashboard update.

TIL

Thx! :+1: