Closed giswqs closed 3 months ago
A proof of concept.
import matplotlib.pyplot as plt from ipyleaflet import Map, Marker, Popup from ipywidgets import Output # Sample data points = [ {'name': 'Point 1', 'location': [40.7128, -74.0060], 'data': [1, 2, 3, 4, 5]}, {'name': 'Point 2', 'location': [34.0522, -118.2437], 'data': [2, 3, 4, 5, 6]}, {'name': 'Point 3', 'location': [37.7749, -122.4194], 'data': [3, 4, 5, 6, 7]}, ] # Function to create the chart def create_chart(data, title): fig, ax = plt.subplots(figsize=(10, 6)) # Adjust the figure size here ax.plot(data) ax.set_title(title) ax.set_xlabel('Time') ax.set_ylabel('Value') output = Output(layout={'width': '400px', 'height': '300px'}) # Adjust the output widget size here with output: plt.show() return output # Create a map m = Map(center=[39.8283, -98.5795], zoom=4) # Define a callback function to create and show the popup def callback_with_popup_creation(point): def f(**kwargs): marker_center = kwargs['coordinates'] marker_name = point['name'] marker_data = point['data'] output = create_chart(marker_data, marker_name) popup = Popup( location=marker_center, child=output, min_width=400, max_width=800 # Adjust the max width here ) m.add_layer(popup) return f # Add points to the map for point in points: marker = Marker(location=point['location'], title=point['name']) marker.on_click(callback_with_popup_creation(point)) m.add_layer(marker) # Display the map m.layout.height = '600px' m
A proof of concept.