散景,条形图和折线图的组合 [英] Bokeh, combination of bar and line chart
本文介绍了散景,条形图和折线图的组合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图在bokeh内的条形图上绘制一条线.我已经尝试过:
I am trying to plot a line on top of a bar chart within bokeh. I have tried:
p1 = figure()...
p1.renderer.append(Bar(...))
p1.renderer.append(Line(...))
show(p1)
到目前为止,我还没有运气.
So far I had no luck.
推荐答案
For your question we can use line and rect.
from bokeh.plotting import figure, output_file, show
from bokeh.models.ranges import Range1d
import numpy
output_file("line_bar.html")
p = figure(plot_width=400, plot_height=400)
# add a line renderer
p.line([1, 2, 3, 4, 5], [6, 7, 6, 4, 5], line_width=2)
# setting bar values
h = numpy.array([2, 8, 5, 10, 7])
# Correcting the bottom position of the bars to be on the 0 line.
adj_h = h/2
# add bar renderer
p.rect(x=[1, 2, 3, 4, 5], y=adj_h, width=0.4, height=h, color="#CAB2D6")
# Setting the y axis range
p.y_range = Range1d(0, 12)
p.title = "Line and Bar"
show(p)
我们得到的情节:
这篇关于散景,条形图和折线图的组合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文