Contact Us!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

| Download
Project: My Project
Views: 35
Image: ubuntu2204
Kernel: Python 3 (system-wide)

Importing the necessary module

Import the Map and Marker classes from the ipyleaflet library:

from ipyleaflet import Map, Marker

Setting map center

Define the center coordinates of the map. Latitude is 52.204793 and longitude is 360.121558:

center =(47.6, -122.3)

Creating the map

Create a map centered at the given coordinates with a zoom level of 12. A higher zoom level means zooming in closer to the map:

m = Map(center=center, zoom=12)

Adding a draggable marker

Add a draggable Marker to the map. This allows updating the marker's location by dragging it on the map:

marker = Marker(location=center, draggable=True) m.add_layer(marker)

Displaying the map

Use the display function to show the map with the draggable marker:

from IPython.display import display display(m)

Updating marker location

Update the marker's location from Python. This can simulate interactions or programmatic updates:

marker.location = (47.6, 122.3)

Observing marker location changes

Define a function that will be triggered when the marker's location changes. This function can be used, for example, to print the new location:

def on_location_changed(event): print('New location:', event['new'])

Connect the function on_location_changed to changes in the marker's location:

marker.observe(on_location_changed, "location")
# python import numpy as np import matplotlib.pyplot as plt from scipy.integrate import odeint # Lorenz equations def lorenz(X, t, sigma=10.0, beta=8.0/3.0, rho=28.0): x, y, z = X dxdt = sigma * (y - x) dydt = x * (rho - z) - y dzdt = x * y - beta * z return [dxdt, dydt, dzdt] # Initial conditions and time points X0 = [1.0, 1.0, 1.0] t = np.linspace(0, 50, 5000) # Solve ODE solution = odeint(lorenz, X0, t) # Plot fig = plt.figure() ax = fig.add_subplot(111, projection='3d') ax.plot(solution[:, 0], solution[:, 1], solution[:, 2]) ax.set_xlabel("X") ax.set_ylabel("Y") ax.set_zlabel("Z") plt.title("Lorenz Attractor") plt.sow()
--------------------------------------------------------------------------- AttributeError Traceback (most recent call last) Cell In[21], line 30 28 ax.set_zlabel("Z") 29 plt.title("Lorenz Attractor") ---> 30 plt.sow() AttributeError: module 'matplotlib.pyplot' has no attribute 'sow'
Image in a Jupyter notebook

Here is a quick e

import numpy as np import matplotlib.pyplot as plt # Parameters n_steps = 100 # Number of steps in one random walk n_iterations = 20 # Number of iterations plt.figure(figsize=(10, 6)) # Simulate and plot each random walk for _ in range(n_iterations): steps = np.random.choice([-1, 1], size=n_steps) # Random steps: -1 or 1 walk = np.cumsum(steps) # Cumulative sum to simulate walk plt.plot(walk, alpha=0.6) plt.title('Random Walk (20 Iterations)') plt.xlabel('Steps') plt.ylabel('Position') plt.grid(True) plt.sow()

Intro


  • σν=γ\sigma-\nu=\gamma