File size: 1,598 Bytes
6efa8c2
542501c
 
 
 
6efa8c2
542501c
 
 
 
 
 
 
 
 
 
6efa8c2
 
 
542501c
 
 
 
 
 
 
 
 
 
 
6efa8c2
542501c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61

from vega_datasets import data
from scipy import stats
from bokeh.plotting import figure
from bokeh.models import ColumnDataSource
import panel as pn
import numpy as np

#import io
#import random
#from typing import List, Tuple

#import aiohttp
#import panel as pn
#from PIL import Image
#from transformers import CLIPModel, CLIPProcessor

pn.extension(design="bootstrap", sizing_mode="stretch_width")


source = data.seattle_weather()

pn.extension()

temp = sorted(source['temp_max'].values)

max_bins = int(np.ceil(max(temp))+ 1 - np.floor(min(temp)))

def create_plot(bandwidth=1.0, bins=max_bins):
    plot = figure(width=300, height=300, toolbar_location=None)
    
    # Histogram
    #bins = np.arange(np.floor(min(temp)), np.ceil(max(temp))+1, 1)
    hist, edges = np.histogram(temp, bins=bins)

    hist = hist / hist.sum()

    quad = plot.quad(top=hist, bottom=0, left=edges[:-1], right=edges[1:],
             fill_color="grey", line_color="white", alpha=0.5)

    # density
    kernel = stats.gaussian_kde(temp, bw_method=bandwidth)
    x = np.linspace(min(temp), max(temp), 100)
    y = kernel(x)
    col_source = ColumnDataSource(data=dict(x=x, y=y))
    line = plot.line('x', 'y', source=col_source, alpha=1.0)
    return plot



bw_widget = pn.widgets.FloatSlider(name="Bandwidth", value=1.0, start=0.03, end=2.0, step=0.02)
bins_widget = pn.widgets.IntSlider(name="Number of Bins", value=max_bins, start=1, end=max_bins)

bound_plot = pn.bind(create_plot, bandwidth=bw_widget, bins=bins_widget)

first_app = pn.Column(bw_widget, bins_widget, bound_plot)

first_app.servable()