Python 散景图的 X 和 Y 轴标签
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24131501/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
X and Y axis labels for Bokeh figure
提问by user3361508
Does anyone know how to add x and y axis title/labels for a Bokeh figure? E.g. X-axis: time, Y-axis: stock price.
有谁知道如何为散景图添加 x 和 y 轴标题/标签?例如 X 轴:时间,Y 轴:股票价格。
Thanks a lot!
非常感谢!
回答by bigreddot
Check out this example: elements.py
看看这个例子:elements.py
You can also now give general plot related options (plot_width
, title
, etc.) to a call to figure(...)
instead of the renderer function (circle
, in that example)
您现在还可以将与绘图相关的一般选项(plot_width
,title
等)提供给调用figure(...)
而不是渲染器函数(circle
在该示例中为 )
回答by thorbjornwolf
As of Bokeh 0.11.1, the user's guide section on axesnow shows how to edit properties of existing axes. The way to do it is the same as before:
从 Bokeh 0.11.1 开始,关于轴的用户指南部分现在显示了如何编辑现有轴的属性。方法和之前一样:
p = figure(width=300, height=300, x_axis_label='Initial xlabel')
p.xaxis.axis_label = 'New xlabel'
回答by tuomastik
This is how you can change the axis label using CustomJS
:
这是您可以使用CustomJS
以下方法更改轴标签的方法:
p = figure(x_axis_label="Initial y-axis label",
y_axis_label="Initial x-axis label")
# ...
# p.xaxis and p.yaxis are lists. To operate on actual the axes,
# we need to extract them from the lists first.
callback = CustomJS(args=dict(xaxis=p.xaxis[0],
yaxis=p.yaxis[0]), code="""
xaxis.axis_label = "Updated x-axis label";
yaxis.axis_label = "Updated y-axis label";
""")
回答by Zeref
from bokeh.plotting import figure, output_file, show
from bokeh.models.annotations import Title
p = figure(plot_width=1300, plot_height=400,x_axis_type="datetime")
p.xaxis.axis_label = 'Time'
p.yaxis.axis_label = 'Stock Price'
p.line(time,stock_price)
t = Title()
t.text = 'Stock Price during year 2018'
p.title = t
show(p)