Py.Cafe

kolibril13/

matplotlib-seed

Matplotlib Seed

DocsPricing
  • app.py
  • requirements.txt
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import solara

import matplotlib.pyplot as plt
import numpy as np

clicks = solara.reactive(0)

@solara.component
def Page():


    def increment():
        clicks.value += 1
        print("clicks", clicks)

    solara.Button(label=f"Clicked: {clicks}", on_click=increment, color="blue")

 
    
    plt.style.use('_mpl-gallery')


    np.random.seed(clicks.value)
    x = 4 + np.random.normal(0, 2, 24)
    y = 4 + np.random.normal(0, 2, len(x))
    sizes = np.random.uniform(15, 80, len(x))
    colors = np.random.uniform(15, 80, len(x))
    fig, ax = plt.subplots()

    ax.scatter(x, y, s=sizes, c=colors, vmin=0, vmax=100)

    ax.set(xlim=(0, 8), xticks=np.arange(1, 8),
        ylim=(0, 8), yticks=np.arange(1, 8))
    plt.show()