![](/img/trans.png)
[英]Select first row with a particular category present in a column of the dataframe
[英]Bokeh table widget with category names in the first column in each row and data in the next column
我想創建一個散景表窗口小部件,其類別名稱在每行的第一列中,數據在第二列中。
有沒有辦法實現這一目標。
謝謝。
您可以將所需的所有內容添加到表中,只要它們在ColumnDataSource中即可。
有關表的更多信息,請參見此處 。
from bokeh.io import show, output_file
from bokeh.models import ColumnDataSource
from bokeh.palettes import Spectral6
from bokeh.plotting import figure
from bokeh.transform import factor_cmap
from bokeh.models.widgets import DataTable, TableColumn
from bokeh.layouts import row
output_file("colormapped_bars.html")
fruits = ['Apples', 'Pears', 'Nectarines', 'Plums', 'Grapes', 'Strawberries']
counts = [5, 3, 4, 2, 4, 6]
source = ColumnDataSource(data=dict(fruits=fruits, counts=counts))
p = figure(x_range=fruits, plot_height=250, toolbar_location=None, title="Fruit Counts")
p.vbar(x='fruits', top='counts', width=0.9, source=source, legend="fruits",
line_color='white', fill_color=factor_cmap('fruits', palette=Spectral6, factors=fruits))
columns = [
TableColumn(field="fruits", title="Fruits"),
TableColumn(field="counts", title="Counts")
]
data_table = DataTable(source=source, columns=columns, width=400, height=280, index_position=None)
p.xgrid.grid_line_color = None
p.y_range.start = 0
p.y_range.end = 9
p.legend.orientation = "horizontal"
p.legend.location = "top_center"
show(row(p, data_table))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.