簡體   English   中英

散景 - 如何將 y 值添加到水平跨度的 y 軸?

[英]Bokeh - how to add y value to y-axis of horizontal Span?

如何在 y 軸上顯示和突出顯示水平跨度的值?

import bokeh as bk
import bokeh.plotting as bkplot
#bkplot.output_notebook() # to show inline

x = np.arange(3)
y = x**2

source = bk.models.ColumnDataSource(dict(x=x, y=y))

p = bkplot.figure(plot_width=500, plot_height=300)

glyph = bk.models.Line(x="x", y="y", line_width=6)
p.add_glyph(source, glyph)

top_span = bk.models.Span(location=3.5, dimension='width', line_color='green', line_width=2)
bottom_span = bk.models.Span(location=1.5, dimension='width', line_color='red', line_width=2)
p.renderers.extend([top_span, bottom_span])

bkplot.show(p)

結果:

在此處輸入圖片說明

想要的結果:

在此處輸入圖片說明

在 Bokeh 的 github 中對這個問題進行了討論: https : //github.com/bokeh/bokeh/issues/7309

因此,尚未實現在軸區域與繪圖區域中的跨度上的標簽。

但是,如果您對繪圖區域中的標簽沒問題,則可能需要使用標簽。 這是我能夠用標簽做的事情:

top_span = bk.models.Span(location=3.5, dimension='width', line_color='green', line_width=2)
top_span_label = bk.models.Label(text_color='green', text=str(top_span.location), x=0, y=top_span.location)
bottom_span = bk.models.Span(location=1.5, dimension='width', line_color='red', line_width=2)
bottom_span_label = bk.models.Label(text_color=bottom_span.line_color, text=str(bottom_span.location), x=0, y=bottom_span.location)
p.renderers.extend([top_span, top_span_label, bottom_span, bottom_span_label])

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM