在 x 轴上截断的散景标签
Bokeh labels truncated on x Axis
我用 Bokeh 创建了一个图表,其中 X 轴的类型为 'datetime'。
不幸的是,X 轴上显示的标签被截断了。
我怎样才能防止这种截断?
这是我的代码:
TOOLS = "pan,wheel_zoom,box_zoom,reset,save"
p = figure(x_axis_type="datetime", tools=TOOLS, plot_width=1000, plot_height=600, title = "Feed")
p.xaxis.formatter=DatetimeTickFormatter(
hours=["%d %B %Y"],
days=["%d %B %Y"],
months=["%d %B %Y"],
years=["%d %B %Y"],
)
p.grid.grid_line_alpha=0.3
p.line(_df.datetime, [i for i in range(len(_df.datetime))], color='firebrick', legend='Fast Ask')
output_file("bokeh.html", title="example")
output_notebook()
show(p) # open a browser
这是图表:
谢谢,
杰拉德
来自reference documentation for DatetimeTickFormatter
:
DatetimeTickFormatter has the following properties (listed together with their default values) that can be used to control the formatting of axis ticks at different scales scales:
microseconds = ['%fus']
milliseconds = ['%3Nms', '%S.%3Ns']
seconds = ['%Ss']
minsec = [':%M:%S']
minutes = [':%M', '%Mm']
hourmin = ['%H:%M']
hours = ['%Hh', '%H:%M']
days = ['%m/%d', '%a%d']
months = ['%m/%Y', '%b%y']
years = ['%Y']
您只设置了最后四个比例,从 hours
开始。但是从您的图片中可以清楚地看出 x 轴范围仅在分钟范围内延伸,因此 Bokeh 使用分钟刻度的默认格式,如上所示。如果你想要一个 "full" 标签用于较小的尺度(例如 hourmin
和 minutes
或更小的尺度),那么你也需要在创建 DatetimeTickFormatter
时配置它们。
我用 Bokeh 创建了一个图表,其中 X 轴的类型为 'datetime'。 不幸的是,X 轴上显示的标签被截断了。 我怎样才能防止这种截断?
这是我的代码:
TOOLS = "pan,wheel_zoom,box_zoom,reset,save"
p = figure(x_axis_type="datetime", tools=TOOLS, plot_width=1000, plot_height=600, title = "Feed")
p.xaxis.formatter=DatetimeTickFormatter(
hours=["%d %B %Y"],
days=["%d %B %Y"],
months=["%d %B %Y"],
years=["%d %B %Y"],
)
p.grid.grid_line_alpha=0.3
p.line(_df.datetime, [i for i in range(len(_df.datetime))], color='firebrick', legend='Fast Ask')
output_file("bokeh.html", title="example")
output_notebook()
show(p) # open a browser
这是图表:
谢谢, 杰拉德
来自reference documentation for DatetimeTickFormatter
:
DatetimeTickFormatter has the following properties (listed together with their default values) that can be used to control the formatting of axis ticks at different scales scales:
microseconds = ['%fus'] milliseconds = ['%3Nms', '%S.%3Ns'] seconds = ['%Ss'] minsec = [':%M:%S'] minutes = [':%M', '%Mm'] hourmin = ['%H:%M'] hours = ['%Hh', '%H:%M'] days = ['%m/%d', '%a%d'] months = ['%m/%Y', '%b%y'] years = ['%Y']
您只设置了最后四个比例,从 hours
开始。但是从您的图片中可以清楚地看出 x 轴范围仅在分钟范围内延伸,因此 Bokeh 使用分钟刻度的默认格式,如上所示。如果你想要一个 "full" 标签用于较小的尺度(例如 hourmin
和 minutes
或更小的尺度),那么你也需要在创建 DatetimeTickFormatter
时配置它们。