私はbokehを初めて使用しており、columnDataSourceの機能を把握しようとしています。それは多くの場所に現れますが、私はその目的とその仕組みが不明です。誰かを照らすことができますか?これが愚かな質問である場合のお詫び...bokehのcolumnDataSourceの目的
6
A
答えて
4
ColumnDataSourceは、Bokehグラフのデータが格納されるオブジェクトです。 ColumnDataSourceを使用せず、Python辞書、pandasデータフレームなどで直接グラフを表示することもできますが、グリフ上にマウスを置いたときにデータ情報を示すポップアップウィンドウを表示するなどの機能では、 ColumnDataSourceでなければ、ポップアップウィンドウはデータを取得できません。他の用途は、データをストリーミングするときである。
ディクショナリとパンダのデータフレームからColumnDataSourceを作成し、ColumnDataSourceを使用してグリフを作成できます。
+1
答えに書いたことをするための小さな例を追加してください。グラフの上にマウスを置いたときにデータを見たい時系列を言う – famargar
1
これは動作するはずです:
import pandas as pd
import bokeh.plotting as bp
from bokeh.models import HoverTool, DatetimeTickFormatter
# Create the base data
data_dict = {"Dates":["2017-03-01",
"2017-03-02",
"2017-03-03",
"2017-03-04",
"2017-03-05",
"2017-03-06"],
"Prices":[1, 2, 1, 2, 1, 2]}
# Turn it into a dataframe
data = pd.DataFrame(data_dict, columns = ['Dates', 'Prices'])
# Convert the date column to the dateformat, and create a ToolTipDates column
data['Dates'] = pd.to_datetime(data['Dates'])
data['ToolTipDates'] = data.Dates.map(lambda x: x.strftime("%b %d")) # Saves work with the tooltip later
# Create a ColumnDataSource object
mySource = bp.ColumnDataSource(data)
# Create your plot as a bokeh.figure object
myPlot = bp.figure(height = 600,
width = 800,
x_axis_type = 'datetime',
title = 'ColumnDataSource',
y_range=(0,3))
# Format your x-axis as datetime.
myPlot.xaxis[0].formatter = DatetimeTickFormatter(days='%b %d')
# Draw the plot on your plot object, identifying the source as your Column Data Source object.
myPlot.circle("Dates",
"Prices",
source=mySource,
color='red',
size = 25)
# Add your tooltips
myPlot.add_tools(HoverTool(tooltips= [("Dates","@ToolTipDates"),
("Prices","@Prices")]))
# Create an output file
bp.output_file('columnDataSource.html', title = 'ColumnDataSource')
bp.show(myPlot) # et voilà.
関連する問題
- 1. Pythonのボケ:columndatasource
- 2. 目的XMLString :: transcodeの目的
- 3. Bokeh Barプロット|
- 4. bokehサーバホストホワイトリスト追加
- 5. Bokeh DatePickerエラー
- 6. インタラクティブBokehチャートの保存
- 7. Bokeh Plotの色付け線
- 8. Bokeh resize - plot overshadows widgets
- 9. Bokehアプリケーション開発ワークフロー
- 10. Bokehプロットを画面に自動的にフィットさせますか?
- 11. Bokehの従属スライダー、コールバックの書き方
- 12. RemoveAll()の目的
- 13. 目的のC
- 14. シングルアサインメントの目的
- 15. スケルトンディレクトリの目的
- 16. DynaValidatorFormの目的
- 17. OptionArgの目的
- 18. オシロスコープの目的
- 19. Bokeh Sliderで画像をスライド
- 20. 属性エラー:TimeSeries Bokehライブラリ
- 21. Bokehプロットとアプリケーションのカスタム画像ページ
- 22. Redisの「evicted_keys」目的
- 23. 目的コードのEXC_BAD_ACCESS
- 24. /var/resource_config.jsonの目的
- 25. webAppRootKeyの目的は?
- 26. セグメントコントロール+目的のナビゲーションバー
- 27. Springフォームコマンドの目的
- 28. プログラミング目的のクリップボードビューア
- 29. IDictionaryインターフェイスの目的
- 30. LINQインクルードの目的
を使用すると、Rまたはパンダ 'DataFrame'オブジェクトに精通している場合は、' ColumnDataSource'は、基本的にその簡単なバージョンです。これは、名前で参照できるデータ(列)の配列の集合です。実際の内部構造は、文字列をリスト/配列にマップする辞書です。データがPythonからBokehJSブラウザー・ライブラリーに移動する主な方法です。 – bigreddot