[英]How can I set the x-label to display datetime in a Bokeh plot?
I have a Excel sheet from which I am extracting the "TIME" and "TEMP" column using pandas library.我有一个 Excel 工作表,我正在使用 Pandas 库从中提取“TIME”和“TEMP”列。 I want to plot temperature vs Time graph for which I have used Bokeh plot .我想绘制温度与时间图,我使用了散景图。 However , the bokeh plot does not show the X-axis values completely .但是,散景图并未完全显示 X 轴值。 Instead it just shows the last few characters of the "TIME" column which is the x-axis .相反,它只显示“时间”列的最后几个字符,即 x 轴。 Please help -请帮忙——
Python code - Python代码 -
import pandas as pd
from bokeh.plotting import figure,output_file,show
from bokeh.models.ranges import Range1d
results=pd.read_excel("test.xls",parse_dates=["TIME"])
print(results['TIME'])
p=figure(plot_width=900,plot_height=500,x_axis_type="datetime",x_axis_label="TIME",y_axis_label="TEMPERATURE" )
p.vbar(x=results["TIME"],top=results["TEMP"],color="red",width=2.4,bottom=0)
p.y_range=Range1d(0,150)
output_file("Scatter_plotting.html")
show(p)
The Excel file - "test.xls" Excel 文件 - “test.xls”
The bokeh plot -散景图 -
As you can see , the bokeh plot x-axis values are not completely plotted .如您所见,散景图 x 轴值并未完全绘制。 Please help .请帮忙。
It appears that the plot is showing your data correctly, but you should check to make sure that results['TIME']
is a Pandas datetime format (your print statement should show dtype: datetime64[ns]
at the bottom).该图似乎正确显示了您的数据,但您应该检查以确保results['TIME']
是 Pandas 日期时间格式(您的打印语句应在底部显示dtype: datetime64[ns]
)。
If the format is correct, then you can control the x-ticks with the following:如果格式正确,则可以使用以下命令控制 x-ticks:
from bokeh.models import DatetimeTickFormatter
p.xaxis.formatter = DatetimeTickFormatter(hourmin = ['%H:%M']) # Or whatever format you want to use...
See the docs here:请参阅此处的文档:
https://docs.bokeh.org/en/latest/docs/reference/models/formatters.html https://docs.bokeh.org/en/latest/docs/reference/models/formatters.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.