日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python交互式和文件式区别_Python中的交互式数据可视化与Bokeh(系列五)

發(fā)布時間:2025/3/15 python 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python交互式和文件式区别_Python中的交互式数据可视化与Bokeh(系列五) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

使用圖例突出顯示數(shù)據(jù)

這將我們帶到本教程中的最終交互性示例:交互式圖例。

在“ 使用字形繪制數(shù)據(jù)”部分中,您了解了在創(chuàng)建繪圖時實現(xiàn)圖例是多么容易。有了這個傳奇,增加交互性只是分配一個問題click_policy。使用單行代碼,您可以使用圖例快速添加任何一種hide或mute數(shù)據(jù)的功能。

在這個例子中,你會看到兩個相同的散點圖,比較勒布朗詹姆斯和凱文杜蘭特的比賽點數(shù)和籃板數(shù)。唯一的區(qū)別是,一個將使用a hide作為其click_policy,而另一個使用mute。

第一步是配置輸出并設(shè)置數(shù)據(jù),從player_statsDataFrame 為每個玩家創(chuàng)建一個視圖:

# Bokeh Librariesfrom bokeh.plotting import figure, showfrom bokeh.io import output_filefrom bokeh.models import ColumnDataSource, CDSView, GroupFilterfrom bokeh.layouts import row# Output inline in the notebookoutput_file('lebron-vs-durant.html', title='LeBron James vs. Kevin Durant')# Store the data in a ColumnDataSourceplayer_gm_stats = ColumnDataSource(player_stats)# Create a view for each playerlebron_filters = [GroupFilter(column_name='playFNm', group='LeBron'), GroupFilter(column_name='playLNm', group='James')]lebron_view = CDSView(source=player_gm_stats, filters=lebron_filters)durant_filters = [GroupFilter(column_name='playFNm', group='Kevin'), GroupFilter(column_name='playLNm', group='Durant')]durant_view = CDSView(source=player_gm_stats, filters=durant_filters)在創(chuàng)建圖形之前,可以將圖形,標記和數(shù)據(jù)中的公共參數(shù)合并到字典中并重復(fù)使用。這不僅可以在下一步中節(jié)省冗余,而且還可以在以后需要時提供一種簡單的方法來調(diào)整這些參數(shù):

# Consolidate the common keyword arguments in dictscommon_figure_kwargs = { 'plot_width': 400, 'x_axis_label': 'Points', 'toolbar_location': None,}common_circle_kwargs = { 'x': 'playPTS', 'y': 'playTRB', 'source': player_gm_stats, 'size': 12, 'alpha': 0.7,}common_lebron_kwargs = { 'view': lebron_view, 'color': '#002859', 'legend': 'LeBron James'}common_durant_kwargs = { 'view': durant_view, 'color': '#FFC324', 'legend': 'Kevin Durant'}現(xiàn)在已經(jīng)設(shè)置了各種屬性,可以以更簡潔的方式構(gòu)建兩個散點圖:

# Create the two figures and draw the datahide_fig = figure(**common_figure_kwargs, title='Click Legend to HIDE Data', y_axis_label='Rebounds')hide_fig.circle(**common_circle_kwargs, **common_lebron_kwargs)hide_fig.circle(**common_circle_kwargs, **common_durant_kwargs)mute_fig = figure(**common_figure_kwargs, title='Click Legend to MUTE Data')mute_fig.circle(**common_circle_kwargs, **common_lebron_kwargs, muted_alpha=0.1)mute_fig.circle(**common_circle_kwargs, **common_durant_kwargs, muted_alpha=0.1)請注意,mute_fig有一個額外的參數(shù)調(diào)用muted_alpha。當mute用作標記時,此參數(shù)控制標記的不透明度click_policy。

最后,click_policy設(shè)置每個圖,它們以水平配置顯示:

# Add interactivity to the legendhide_fig.legend.click_policy = 'hide'mute_fig.legend.click_policy = 'mute'# Visualizeshow(row(hide_fig, mute_fig))

一旦傳說中的地方,所有你需要做的是分配任一hide或mute到人物的click_policy屬性。這將自動將您的基本圖例轉(zhuǎn)換為交互式圖例。

另請注意,特別是mute,LeBron James和Kevin Durant muted_alpha的相應(yīng)circle字形中設(shè)置了附加屬性。這決定了圖例互動驅(qū)動的視覺效果。

有關(guān)Bokeh中所有事物交互的更多信息,在Bokeh用戶指南中添加交互是一個很好的起點。

總結(jié)和后續(xù)步驟

恭喜!你已經(jīng)完成了本教程的結(jié)尾。

您現(xiàn)在應(yīng)該擁有一套很棒的工具來開始使用Bokeh將數(shù)據(jù)轉(zhuǎn)換為漂亮的交互式可視化。

你學會了如何:

配置腳本以呈現(xiàn)為靜態(tài)HTML文件或Jupyter Notebook實例化和自定義figure()對象使用字形構(gòu)建可視化使用。訪問和過濾您的數(shù)據(jù) ColumnDataSource在網(wǎng)格和選項卡式布局中組織多個圖添加不同形式的交互,包括選擇,懸停操作,鏈接和交互式圖例為了更好地探索Bokeh的功能,官方的Bokeh用戶指南是深入了解更高級主題的絕佳場所。我還建議您查看Bokeh的畫廊,了解大量的例子和靈感。

Bokeh 網(wǎng)站文檔https://bokeh.pydata.org/en/latest/docs/reference.html

總結(jié)

以上是生活随笔為你收集整理的python交互式和文件式区别_Python中的交互式数据可视化与Bokeh(系列五)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。