6.3 效果图:

文章插图
6.4 图形总体
6.4.1 代码:
from bokeh.core.enums import MarkerTypefrom bokeh.layouts import rowfrom bokeh.models import ColumnDataSource, Panel, Tabsfrom bokeh.plotting import figure, output_file, showfrom bokeh.sampledata.iris import flowerssource = 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 ptabs = []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 效果图
文章插图
===一般基本作图是小白和普通人需要的掌握的,下次重点讲===
7 机器学习:scikit-learn project
========================
7.1 代码:
import numpy as npfrom sklearn import cluster, datasetsfrom sklearn.preprocessing import StandardScalerfrom bokeh.layouts import column, rowfrom bokeh.plotting import figure, output_file, showprint("nn*** This example may take several seconds to run before displaying. ***nn")print("nn*** 该示例展示前需要等待几秒. ***nn")N = 50000PLOT_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 algorithmsdbscan= 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 ALGplots =[]for dataset in (noisy_circles, noisy_moons, blobs1, blobs2):X, y = datasetX = StandardScaler().fit_transform(X)# predict cluster membershipsalgorithm.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 plotslayout = column(row(plots[:2]), row(plots[2:]))output_file("clustering.html", title="clustering with sklearn")show(layout)7.2 效果图:
文章插图
===自己整理并分享出来===
喜欢的就点赞、转发、评论、关注和收藏 。
推荐阅读
- 为什么你写的代码总是有 Bug?用它来保证 Go 代码质量
- 淘宝轮播图一般是什么内容 淘宝直通车创意轮播和优选哪个好
- 如何提高搜商 淘商机怎么用
- 收下这十点C语言入门须知
- 视频常用的H264和H265是啥?
- 大红袍是绿茶还是红茶,大红袍茶好不好呢
- 蒙汉情深何忍别天涯话斜阳的意思是什么?
- 925银是纯银吗?
- 郭子仪最后的结局是怎样的?
- 淘宝店铺商标注册号申请号是什么 怎么申请靓号
