范文健康探索娱乐情感热点
投稿投诉
热点动态
科技财经
情感日志
励志美文
娱乐时尚
游戏搞笑
探索旅游
历史星座
健康养生
美丽育儿
范文作文
教案论文
国学影视

Bokeh是一个专门针对Web浏览器的交互式可视化Python库

  1 说明:
  =====
  1.1 Bokeh是专门针对Web浏览器的交互式、可视化Python绘图库。
  1.2 Bokeh,可以做出像D3.js简洁漂亮的交互可视化效果,但是使用难度低于D3.js。
  1.3 不需要使用Javascript。
  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 图:
  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 图:
  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 图:
  ===基本作图方便,优美;比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(p, attributes=[]):     style = "float: left; clear: left; font-size: 13px"     return CustomJS(args=dict(p=p), 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 = "" + cb_obj.event_name + "(" + args.join(", ") + ")n";         var text = p.text.concat(line);         var lines = text.split("n")         if (lines.length > 35)             lines.shift();         p.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) #容器实例化,宽 p = Div(width=1000) button = Button(label="Button", button_type="success", width=300) layout = column(button, row(p, p)) #注册事件回调 #按钮事件 button.js_on_event(events.ButtonClick, display_event(p)) # LOD事件 p.js_on_event(events.LODStart, display_event(p)) p.js_on_event(events.LODEnd, display_event(p)) # Point events点事件 point_attributes = ["x","y","sx","sy"] p.js_on_event(events.Tap,       display_event(p, attributes=point_attributes)) p.js_on_event(events.DoubleTap, display_event(p, attributes=point_attributes)) p.js_on_event(events.Press,     display_event(p, attributes=point_attributes)) p.js_on_event(events.PressUp,   display_event(p, attributes=point_attributes)) # Mouse wheel event p.js_on_event(events.MouseWheel, display_event(p,attributes=point_attributes+["delta"])) # Mouse move, enter and leave p.js_on_event(events.MouseMove,  display_event(p, attributes=point_attributes)) p.js_on_event(events.MouseEnter, display_event(p, attributes=point_attributes)) p.js_on_event(events.MouseLeave, display_event(p, attributes=point_attributes)) # Pan events pan_attributes = point_attributes + ["delta_x", "delta_y"] p.js_on_event(events.Pan,      display_event(p, attributes=pan_attributes)) p.js_on_event(events.PanStart, display_event(p, attributes=point_attributes)) p.js_on_event(events.PanEnd,   display_event(p, attributes=point_attributes)) # Pinch events pinch_attributes = point_attributes + ["scale"] p.js_on_event(events.Pinch,      display_event(p, attributes=pinch_attributes)) p.js_on_event(events.PinchStart, display_event(p, attributes=point_attributes)) p.js_on_event(events.PinchEnd,   display_event(p, attributes=point_attributes)) # Selection events p.js_on_event(events.SelectionGeometry, display_event(p, attributes=["geometry", "final"])) show(layout)
  6.3 效果图:
  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 效果图
  ===一般基本作图是小白和普通人需要的掌握的,下次重点讲===
  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("  *** This example may take several seconds to run before displaying. ***  ") print("  *** 该示例展示前需要等待几秒. ***  ") 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 效果图:
  ===自己整理并分享出来===
  喜欢的就点赞、转发、评论、关注和收藏。

这4道菜,营养又美味,让孩子跟上春天的末班车,个子长高高春天,作为一年四季的起点,是孩子长个的关键时节,春季营养补充没有跟上的,千万不要错过,春末长个的冲刺阶段,好好利用这个一年一度的重要时节,帮助孩子长高。孩子身高不达标会有什么影响?明天和意外,永远不知道哪个先来,该如何和孩子谈论死亡死亡不是生命的终点,遗忘才是。寻梦环游记死和亡在字面上的含义是不一样的。死是指安静静止不再有生机和活力,而亡特指被忘记。有研究发现,人临死的时候更多不怕死而怕亡,所以人们喜欢用碑文要是你头胎是个儿子,当你第一时间知道二胎又是个儿子的时候会有什么想法?我的第一胎是一个儿子,当我怀孕三个月的时候,我通过做B超又知道自己怀了儿子,当时内心很复杂,我想要儿女双全,所以说我一直在期盼出现扭转,希望B超做的不是很准确,希望二胎是一个女宝宝有个社恐宝宝是什么体验?当娃出现几个征兆,爸妈就该警惕了人是在关系中成长起来的。我们来到这个人世间,不是一座孤岛,而是需要跟不同的人建立起联系,如果你想在人群中吃香,社交能力就显得尤为重要。本文配图均源于网络,图文均无关对于社恐人士来说宝宝身体发出4个信号很重要家长千万不能粗心大意只有当了父母以后才能体会到,每天都提心吊胆的心情。当宝宝出生的第一秒开始,由于缺少经验,宝爸宝妈便开始了无休无止的担忧,担心缺这担心缺那,担心磕着碰着,担心吃的不香,担心睡得不好。孩子一直在饥饿,父母竟然不知道,每天都让孩子吃得挺饱的!一孩子的成长绝对不能延误孩子是父母的眼珠子,孩子的健康成长绝对不能延误的。在孩童时期,如果由于家长的疏忽或无知而影响了孩子的身体发育和智力发展,那将是父母后悔一辈子的事。有这么一对误区看动画片会让孩子思维迟钝?很多家长喜欢给孩子找价值高,有教育意义的动画片。与此同时,也有很多声音跳出来说看动画片会让孩子思维迟钝,不应该再让孩子看了。究竟哪种做法才对?看还是不看?首先看看动画片会让孩子思维奶粉喂养的宝宝,该不该按照参考比例冲调?看月龄。一段以内绝对按照标准来泡。二段需要额外补充水分了,所以有时候我会直接把奶粉泡稀,一餐几勺不变,多加适量水3050ml这样。三段说是可喝可不喝的,因为这时候饭菜肉啥都能吃了。生活中,老实人千万别做哪些傻事?1连续请一个人吃饭喝酒,总是你买单。2一群人吃饭,起哄让你买单,你去了。3半途你朋友喊你过去吃饭,你去了,饭后喊你买单。做出以上的举动,却没有得到任何回报,更傻。4别人不愿意做的事怎么筛查孩子是不是自闭症?自闭症的核心障碍是什么?自闭症谱系障碍的警示标志很多年前,我和朋友一起参加晚宴。他们华丽的2。5岁儿子在没有停下来的情况下跑来跑去,其中一位客人评论说他太可爱了,就像一个小机器人一样跑来跑去。几个月后,我分娩时该吃点什么?自然分娩时从有规律的子宫收缩到胎儿娩出,初产妇大约要经历1617个小时,体力消耗很大。有的孕妇担心没有体力或生完宝宝坐月子不能随心所欲吃东西,在动产前特意吃很多平时爱吃的油腻辛辣刺
辞去北京的工作,结束分居,这是幸福的婚姻吗?刚结婚半年的李伟(化名)本应该处在享受婚姻的幸福之中,他却愁容满面。原来是他的妻子又一次提起让他辞去北京的工作,回到老家和妻子一起做妻子现在的工作。李伟是一名设计师,在北京已经有八行到水穷处,坐看云起时亲爱的朋友,对于我等众生而言,苦难往往并非最初就可以轻而易举心平气和悦纳的,心理上多要经历否认愤怒幻想沮丧才最终接受。沮丧期是更为愤怒和悲伤的阶段。遭遇了生命中大挫折,我,价值何在为什么有的人历经坎坷却没有得抑郁症?昨天回答了一个朋友提问,为什么父母年轻时生活艰辛却没有得抑郁症,觉得需要再多说一些。是否得抑郁症和人客观的生活经历没有必然联系。比如生活极度贫困或遭遇过性侵家暴等创伤性经历的确可能因侄子的一句话,大龄剩女决定把自己嫁出去我的报应来了白活了导语你听过什么童言无忌的话吗?那些威力不大,但侮辱有极强的话语,说者无心,听者有意。你以为这是孩子说的童言无忌,但是透过事实你才发现,这些不是孩子想说的,而是大人嘴边的口头禅。雅里宝爸带3个月大的娃打针,自己哭成泪人,网友医生打错人了?孩子是爱情的结晶,随着孩子那声娇嫩的啼哭,家,因孩子变得热闹起来,因孩子家里充满了欢声笑语,因孩子我们体会了不一样的人生。每个孩子都是落入凡间的天使,他们有时乖巧,有时调皮,有时暖孩子发烧别慌!崔玉涛儿童医院专家的建议我帮你整理好了进入夏季,暑湿邪气正盛,中医亦有苦夏一说。孩子自身调节能力弱,身体有小恙是常事,发烧就是最常见表现。很多家长谈烧色变,像应对洪水猛兽般恐慌,带来的往往是不恰当的治疗。孩子体温多少度老板11岁的儿子摆摊卖玩具,不就是赚零花钱吗?知道真相后我愣了导语有欧洲巴菲特之称的著名理财专家博多舍费尔曾在财务自由之路一书中说直接给孩子钱是不负责任的。给孩子解释金钱和富裕的概念可能会花费一些时间,但却可以使孩子拥有大多数人没有的宝贵机会非暴力沟通,心理咨询师说出5个真相,希望你能听进去导语两个人在一起,天天吵架,没有理解,只有相互的埋怨,只有一味的争吵,这种日子只能叫折磨两个人在一起,只是为了生活,而生活中没有节日,没有惊喜,没有感动,没有关爱,没有呵护,没有浪小舍得南建龙为何不花8000元请保姆,偏偏却要抛妻弃子呢?导语婚姻是一场合作,你永远要思考怎么样让自己随时保持价值,如何满足对方的核心要求。在最近热播的电视剧小舍得里,也是如此。今天给大家聊一聊小舍得第二期,老伴老伴老来伴,张国立饰演的南儿子和儿媳妇离婚后,儿媳妇的做法让人心疼?导语都说婆婆是婆婆,不可能成为亲妈,儿媳是儿媳,不可能成为亲女儿。自古以来婆媳关系多不和,不是婆婆有多坏,也不是儿媳有多么不孝顺,只是站的角度不同,看待问题的方式不同罢了。涂磊曾说姐姐给弟弟取名小山芋,知道名字的由来后,38岁的她愣了导语知否里有一句台词儿女众多的人家,父母要一碗水端平,才能家宅宁静。虽说手心手背都是肉,但是手心手背的肉还真的不一样,当父母的想把一碗水端平,那可不是一件容易的。但不管容易与否,父