Overlay in Python is not working when I try to combine two plots

19 views Asked by At

When I try to combine two plots by using * in Python, I don't get the correct plot. I only get a single point, but I am supposed to get points and connections between them. This is my code:

import geopandas as gpd
import holoviews as hv
import hvplot.pandas
from shapely.geometry import Point

cluster_means['geometry'] = [Point(lon, lat) for lon, lat in zip(cluster_means['longitude'], cluster_means['latitude'])]
geo_cluster_means = gpd.GeoDataFrame(cluster_means, geometry='geometry', crs='EPSG:4326')

points_plot = geo_cluster_means.hvplot.points(x='longitude', y='latitude', geo=True, color='red', size=100).opts(width=800, height=600)

lines_overlay = hv.Overlay()


for index, row in df_counts.iterrows():
    origin_coords = geo_cluster_means.loc[geo_cluster_means['cluster'] == row['origin']]['geometry'].iloc[0]
    dest_coords = geo_cluster_means.loc[geo_cluster_means['cluster'] == row['destination']]['geometry'].iloc[0]

    lines = hv.Curve([(origin_coords.x, origin_coords.y), (dest_coords.x, dest_coords.y)] * row['n'])
    lines_overlay *= lines

combined_plot = lines_overlay.opts(width=800, height=600) * points_plot
combined_plot

When I use + instead of * i get two separate plots which are what I want to combine. I also don't get n lines from origin to destination, I only get 1 line.

0

There are 0 answers