日日操夜夜添-日日操影院-日日草夜夜操-日日干干-精品一区二区三区波多野结衣-精品一区二区三区高清免费不卡

公告:魔扣目錄網為廣大站長提供免費收錄網站服務,提交前請做好本站友鏈:【 網站目錄:http://www.ylptlb.cn 】, 免友鏈快審服務(50元/站),

點擊這里在線咨詢客服
新站提交
  • 網站:51998
  • 待審:31
  • 小程序:12
  • 文章:1030137
  • 會員:747

1 說明:

=====

1.1 Bokeh是專門針對Web瀏覽器的交互式、可視化Python繪圖庫。

1.2 Bokeh,可以做出像D3.js簡潔漂亮的交互可視化效果,但是使用難度低于D3.js。

1.3 不需要使用JAVAscript。

Bokeh是一個專門針對Web瀏覽器的交互式可視化Python庫

 

2 官網:

======

https://docs.bokeh.org/en/latest/
https://github.com/bokeh/bokeh

3 安裝:

=====

pip install bokeh
#本機安裝
sudo pip3.8 install bokeh

4 環境:

=====

華為筆記本電腦、深度deepin-linux操作系統、python3.8和微軟vscode編輯器。

5 靜態基本作圖:

============

5.1 柱狀圖:

5.1.1 代碼:

from bokeh.io import output_file, show
from bokeh.plotting import figure
#數據,支持中文
fruits = ['蘋果', 'Pears', 'Nectarines', 'Plums', 'Grapes', 'Strawberries']
counts = [5, 3, 4, 2, 4, 6]
#繪圖
p = figure(x_range=fruits, plot_height=350, title="Fruit Counts",
           toolbar_location=None, tools="")
#柱狀圖,vbar是指垂直柱狀圖
p.vbar(x=fruits, top=counts, width=0.9)
#導出文件:文件名和指定路徑,
#注意沒有這一行,也會自動在代碼所在的生成同名的html文件
#output_file("/home/xgj/Desktop/bokeh/bar_basic.html")
#展示圖
show(p)

5.1.2 圖:

Bokeh是一個專門針對Web瀏覽器的交互式可視化Python庫

 


Bokeh是一個專門針對Web瀏覽器的交互式可視化Python庫

 

5.2 折線圖

5.2.1 代碼:

from bokeh.io import output_file, show
from bokeh.plotting import figure
#數據,支持中文
fruits = ['蘋果', 'Pears', 'Nectarines', 'Plums', 'Grapes', 'Strawberries']
counts = [5, 3, 4, 2, 4, 6]
#繪圖
p = figure(x_range=fruits, plot_height=350, title="Fruit Counts",
           toolbar_location=None, tools="")
#柱狀圖
p.line(x=fruits, y=counts)
#展示圖
show(p)

5.2.2 圖:

Bokeh是一個專門針對Web瀏覽器的交互式可視化Python庫

 

5.3 散點圖:

5.3.1 代碼:

#from bokeh.io import output_file, show
from bokeh.plotting import figure,output_file, show  #同上
#數據,支持中文
fruits = ['蘋果', 'Pears', 'Nectarines', 'Plums', 'Grapes', 'Strawberries']
counts = [5, 3, 4, 2, 4, 6]
#繪圖
p = figure(x_range=fruits, plot_height=350, title="Fruit Counts",
           toolbar_location=None, tools="")
#柱狀圖
p.scatter(x=fruits, y=counts,size=20, fill_color="#74add1")
#展示圖
show(p)

5.3.2 圖:

Bokeh是一個專門針對Web瀏覽器的交互式可視化Python庫

 

===基本作圖方便,優美;比matplotlib簡單,暫時介紹到這里===

6 高級作圖:

=========

6.1 js_events:調用js事件

6.2 代碼:

import numpy as np
from bokeh import events
from bokeh.io import output_file, show
from bokeh.layouts import column, row
from bokeh.models import Button, CustomJS, Div
from bokeh.plotting import figure
#定義js和事件
def display_event(div, attributes=[]):
    style = 'float: left; clear: left; font-size: 13px'
    return CustomJS(args=dict(div=div), code="""
        var attrs = %s;
        var args = [];
        for (var i = 0; i < attrs.length; i++) {
            var val = JSON.stringify(cb_obj[attrs[i]], function(key, val) {
                return val.toFixed ? Number(val.toFixed(2)) : val;
            })
            args.push(attrs[i] + '=' + val)
        }
        var line = "<span style=%r><b>" + cb_obj.event_name + "</b>(" + args.join(", ") + ")</span>\n";
        var text = div.text.concat(line);
        var lines = text.split("\n")
        if (lines.length > 35)
            lines.shift();
        div.text = lines.join("\n");
    """ % (attributes, style))
#數據
N = 4000
x = np.random.random(size=N) * 100
y = np.random.random(size=N) * 100
radii = np.random.random(size=N) * 1.5
colors = [
    "#%02x%02x%02x" % (int(r), int(g), 150) for r, g in zip(50+2*x, 30+2*y)
]

p = figure(tools="pan,wheel_zoom,zoom_in,zoom_out,reset,tap,lasso_select,box_select")
#調用散點圖
p.scatter(x, y, radius=radii,
          fill_color=colors, fill_alpha=0.6,
          line_color=None)
#容器實例化,寬
div = Div(width=1000)
button = Button(label="Button", button_type="success", width=300)
layout = column(button, row(p, div))
#注冊事件回調
#按鈕事件
button.js_on_event(events.ButtonClick, display_event(div))
# LOD事件
p.js_on_event(events.LODStart, display_event(div))
p.js_on_event(events.LODEnd, display_event(div))
# Point events點事件
point_attributes = ['x','y','sx','sy']
p.js_on_event(events.Tap,       display_event(div, attributes=point_attributes))
p.js_on_event(events.DoubleTap, display_event(div, attributes=point_attributes))
p.js_on_event(events.Press,     display_event(div, attributes=point_attributes))
p.js_on_event(events.PressUp,   display_event(div, attributes=point_attributes))
# Mouse wheel event
p.js_on_event(events.MouseWheel, display_event(div,attributes=point_attributes+['delta']))
# Mouse move, enter and leave
p.js_on_event(events.MouseMove,  display_event(div, attributes=point_attributes))
p.js_on_event(events.MouseEnter, display_event(div, attributes=point_attributes))
p.js_on_event(events.MouseLeave, display_event(div, attributes=point_attributes))
# Pan events
pan_attributes = point_attributes + ['delta_x', 'delta_y']
p.js_on_event(events.Pan,      display_event(div, attributes=pan_attributes))
p.js_on_event(events.PanStart, display_event(div, attributes=point_attributes))
p.js_on_event(events.PanEnd,   display_event(div, attributes=point_attributes))
# Pinch events
pinch_attributes = point_attributes + ['scale']
p.js_on_event(events.Pinch,      display_event(div, attributes=pinch_attributes))
p.js_on_event(events.PinchStart, display_event(div, attributes=point_attributes))
p.js_on_event(events.PinchEnd,   display_event(div, attributes=point_attributes))
# Selection events
p.js_on_event(events.SelectionGeometry, display_event(div, attributes=['geometry', 'final']))
show(layout)

6.3 效果圖:

Bokeh是一個專門針對Web瀏覽器的交互式可視化Python庫

 

6.4 圖形總體

6.4.1 代碼:

from bokeh.core.enums import MarkerType
from bokeh.layouts import row
from bokeh.models import ColumnDataSource, Panel, Tabs
from bokeh.plotting import figure, output_file, show
from bokeh.sampledata.iris import flowers

source = ColumnDataSource(flowers)
def make_plot(title, marker, backend):
    p = figure(title=title, plot_width=350, plot_height=350, output_backend=backend)
    p.scatter("petal_length", "petal_width", source=source,
              color='blue', fill_alpha=0.2, size=12, marker=marker)
    return p
tabs = []
for marker in MarkerType:
    p1 = make_plot(marker, marker, "canvas")
    p2 = make_plot(marker + ' SVG', marker, "svg")
    p3 = make_plot(marker + ' GL', marker, "webgl")
    tabs.Append(Panel(child=row(p1, p2, p3), title=marker))
#output_file("marker_compare.html", title="Compare regular, SVG, and WebGL markers")
show(Tabs(tabs=tabs))

6.4.2 效果圖

Bokeh是一個專門針對Web瀏覽器的交互式可視化Python庫

 

===一般基本作圖是小白和普通人需要的掌握的,下次重點講===

7 機器學習:scikit-learn project

========================

7.1 代碼:

import numpy as np
from sklearn import cluster, datasets
from sklearn.preprocessing import StandardScaler
from bokeh.layouts import column, row
from bokeh.plotting import figure, output_file, show
print("nn*** This example may take several seconds to run before displaying. ***nn")
print("nn*** 該示例展示前需要等待幾秒. ***nn")
N = 50000
PLOT_SIZE = 400
# generate datasets.
np.random.seed(0)
noisy_circles = datasets.make_circles(n_samples=N, factor=.5, noise=.04)
noisy_moons = datasets.make_moons(n_samples=N, noise=.05)
centers = [(-2, 3), (2, 3), (-2, -3), (2, -3)]
blobs1 = datasets.make_blobs(centers=centers, n_samples=N, cluster_std=0.4, random_state=8)
blobs2 = datasets.make_blobs(centers=centers, n_samples=N, cluster_std=0.7, random_state=8)

colors = np.array([x for x in ('#00f', '#0f0', '#f00', '#0ff', '#f0f', '#ff0')])
colors = np.hstack([colors] * 20)
# create clustering algorithms
dbscan   = cluster.DBSCAN(eps=.2)
birch    = cluster.Birch(n_clusters=2)
means    = cluster.MiniBatchKMeans(n_clusters=2)
spectral = cluster.SpectralClustering(n_clusters=2, eigen_solver='arpack', affinity="nearest_neighbors")
affinity = cluster.AffinityPropagation(damping=.9, preference=-200)
# change here, to select clustering algorithm (note: spectral is slow)
algorithm = dbscan  # <- SELECT ALG
plots =[]
for dataset in (noisy_circles, noisy_moons, blobs1, blobs2):
    X, y = dataset
    X = StandardScaler().fit_transform(X)
    # predict cluster memberships
    algorithm.fit(X)
    if hasattr(algorithm, 'labels_'):
        y_pred = algorithm.labels_.astype(np.int)
    else:
        y_pred = algorithm.predict(X)

    p = figure(output_backend="webgl", title=algorithm.__class__.__name__,
               plot_width=PLOT_SIZE, plot_height=PLOT_SIZE)

    p.scatter(X[:, 0], X[:, 1], color=colors[y_pred].tolist(), alpha=0.1,)
    plots.append(p)
# generate layout for the plots
layout = column(row(plots[:2]), row(plots[2:]))
output_file("clustering.html", title="clustering with sklearn")
show(layout)

7.2 效果圖:

Bokeh是一個專門針對Web瀏覽器的交互式可視化Python庫

 

===自己整理并分享出來===

喜歡的就點贊、轉發、評論、關注和收藏。

分享到:
標簽:瀏覽器
用戶無頭像

網友整理

注冊時間:

網站:5 個   小程序:0 個  文章:12 篇

  • 51998

    網站

  • 12

    小程序

  • 1030137

    文章

  • 747

    會員

趕快注冊賬號,推廣您的網站吧!
最新入駐小程序

數獨大挑戰2018-06-03

數獨一種數學游戲,玩家需要根據9

答題星2018-06-03

您可以通過答題星輕松地創建試卷

全階人生考試2018-06-03

各種考試題,題庫,初中,高中,大學四六

運動步數有氧達人2018-06-03

記錄運動步數,積累氧氣值。還可偷

每日養生app2018-06-03

每日養生,天天健康

體育訓練成績評定2018-06-03

通用課目體育訓練成績評定