简体   繁体   English

如何设置 x 标签以在散景图中显示日期时间?

[英]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”

eExcel 源文件

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.

相关问题 如何将 x 轴设置为散景图上的日期时间? - How can I set the x-axis as datetimes on a bokeh plot? 如何将共享的 x 标签和 y 标签添加到使用 pandas plot 创建的图中 - How to add a shared x-label and y-label to a plot created with pandas plot 绘制带有x标签的图形是月份和日期 - plot a graph with its x-label is month and date 我怎么知道我的直方图中的 x-label 和 y-label 在 python 中是什么? - How do I know what the x-label and y-label in my histogram are in python? 如何在散景悬停格式化程序上设置自定义日期时间模式? - How can I set custom datetime pattern on Bokeh hover formatter? 无法使用日期时间x轴在Bokeh中绘制热图 - Can't plot heatmap in Bokeh with datetime x axis Matplotlib:如何指定 x 标签边界框的宽度 - Matplotlib: how to specify width of x-label bounding box 时间序列根据CSV数据(时间戳和事件)绘制:x标签常量 - Timeseries plot from CSV data (Timestamp and events): x-label constant 为什么图表的标题和 x-label 都相同,即使我已经将它们包含在 for 循环中? - Why the title and the x-label for the charts are all the same even I already included them in the for loop? 如何在散景中设置日期时间轴的语言? - How do I set language of datetime axis in bokeh?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM