我对 python 比较陌生,我正在使用 bokeh 创建一个绘制一些时间序列数据的 html 文件。
我想将 x 轴刻度格式化为“DD/MM HH:SS”。我正在编写代码的简化版本:
from bokeh.plotting import figure, output_file, save, show
from bokeh.models import DatetimeTickFormatter
import datetime as dt
t=[dt.datetime(2017, 1, 9, 16, 14, 10),dt.datetime(2017, 1, 9, 16, 15, 20)]
Temp=[200,210]
output_file("Burner SPC test.html")
p1=figure(title="Tip1 TC", x_axis_label="Time", y_axis_label="Temp Diff", x_axis_type="datetime")
p1.line(t,Temp)
p1.xaxis.formatter=DatetimeTickFormatter(formats=dict(
days=["%??"],
months=["%??"],
hours=["%???"],
minutes=["%???"])) #not sure how to format here to get the desired output
show(p1)
非常感谢任何帮助。 提前致谢。
最佳答案
DateTimeTickFormatter 不再期待字典(如 bigreddot here 所述)。在我的 Bokeh 版本 (1.0.4) 中,它通过删除“formats=dict()”并提供格式字符串来工作。
p1.xaxis.formatter=DatetimeTickFormatter(days="%m/%d %H:%M",
months="%m/%d %H:%M",
hours="%m/%d %H:%M",
minutes="%m/%d %H:%M")
两者都可以。对所有这些使用相同的格式字符串,或使用单独的格式字符串。放大时轴的格式会调整。
from bokeh.plotting import figure, output_file, save, Show
from bokeh.models import DatetimeTickFormatter
import datetime as dt
import datetime as dt
t=[dt.datetime(2017, 1, 9, 16, 14, 10),dt.datetime(2017, 1, 10, 17, 15, 20)]
Temp=[200,210]
output_file("Burner SPC test.html")
p1=figure(title="Tip1 TC", x_axis_label="Time", y_axis_label="Temp Diff", x_axis_type="datetime")
p1.line(t,Temp)
p1.xaxis.formatter=DatetimeTickFormatter(days="%m/%d",
hours="%H",
minutes="%H:%M")
show(p1)
关于python - 如何使用 Bokeh datetimetickformatter 自定义刻度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41579840/