Zahlen mit gemeinsamer Legende - BokehPython

Python-Programme
Anonymous
 Zahlen mit gemeinsamer Legende - Bokeh

Post by Anonymous »

Ich möchte zwei Zahlen aus demselben Datenrahmen mit einer gemeinsamen Legende machen.source = ColumnDataSource(data)
hist_source = ColumnDataSource(data)

p1 = figure(x_axis_type='datetime', title='', height=430, width=900, y_minor_ticks=5)
hist = figure(title='', x_axis_label='occurances', y_axis_label='Label', height=430, width=200)

columns = [col for col in data.columns]

for i, col in enumerate(columns):
circle = p1.circle(x='timestamp', y=col, size=3, color=CUSTOM, alpha=0.8, source=source)
quad = hist.quad(top=col, bottom=0, left='timestamp', right='timestamp', source=hist_source, color=CUSTOM, alpha=0.8)

legend = Legend(items=p1.legend[0].items, location='bottom_left', orientation='horizontal', ncols=3)
legend.click_policy = 'hide'

p1.add_layout(legend, 'below')

p = row(p1, hist)
< /code>
Dann habe ich diese Frage gesehen (wie man eine Legende hinzufügt, die mehrere Bokeh -Zahlen steuert?) Und versuchte, sie zu replizieren: < /p>
source = ColumnDataSource(data)
p1 = figure(x_axis_type='datetime', title='', height=430, width=900, y_minor_ticks=5)

columns = [col for col in data.columns]

hist_source = ColumnDataSource(data={'top': [], 'bottom': [], 'left': [], 'right': [], 'group': []})
hist = figure(title='', x_axis_label='Cycles', y_axis_label='Label', height=430, width=200)
hist.y_range = p1.y_range

legend_items = []
renderers = []
color_list = []
for i, col in enumerate(columns):
circle = p1.circle(x='timestamp', y=col, size=3, color=CUSTOM,
alpha=0.8, legend_label=col, source=source)
quad = hist.quad(top='top', bottom='bottom', left='left', right='right',
source=hist_source, color=CUSTOM, alpha=0.8)
legend_items.append((col, [circle, quad]))
color_list.append(CUSTOM)
renderer_list = [circle, quad]
legend_items = [LegendItem(label=color, renderers=[renderer for renderer in renderer_list if renderer.glyph.line_color==color]) for color in set(color_list)]

dum_fig=figure(width=100, height=100, outline_line_alpha=0, toolbar_location=None)
for fig_component in [dum_fig.grid[0], dum_fig.ygrid[0], dum_fig.xaxis[0], dum_fig.yaxis[0]]:
fig_component.visible=False
dum_fig.renderers += renderer_list
dum_fig.add_layout(Legend(click_policy='hide'))

figrid = gridplot([p1, hist], ncols=2)
p=gridplot([[figrid, dum_fig]], toolbar_location=None)
< /code>
Aber es funktioniert nicht wie erwartet: Ich habe eine Legende, aber wenn ich darauf klicke, passiert nichts. Vielen Dank im Voraus,

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post