Reputation: 2169
I m building a charts page using bokeh to plot them. I have some Line chart where I need to plot on x-axis the number of week of the year.
So this is the result that I m able to build:
As you can see there are some poin on X axis with 09/2023 and 10/2023 at last point.
It is possible to display only the point where are the values, like this?
This is the code I used to build this chart:
plotIndicatori = figure(plot_width=int(850), plot_height=int(165),
tools="pan,box_zoom,reset",
title=nomeIndicatore,
x_axis_type="datetime")
plotIndicatori.toolbar.logo = None
plotIndicatori.y_range.start = 0
plotIndicatori.y_range.end = rangeMax + 5
plotIndicatori.line(x='DateTime', y='Valore', color="navy", alpha=1, source=sourceIndicatori)
plotIndicatori.circle(x='DateTime', y='Valore', color="navy", alpha=1, source=sourceIndicatori)
# plotSfera.axis.visible = False
plotIndicatori.xgrid.grid_line_color = None
plotIndicatori.outline_line_color = background
plotIndicatori.border_fill_color = background
plotIndicatori.background_fill_color = background
Upvotes: 0
Views: 532
Reputation: 6347
The DatetimeTickFormatter
from bokeh offers you multiple options to format the date string on your x-axis. The options %U
, %V
and %W
all offer the number of weeks. You have to select the one that works best for you. Read the docs to get the complete list of available options.
import pandas as pd
df = pd.DataFrame(
{'data':list(range(367))},
index=pd.date_range('2020-01-01', '2021-01-01', freq='D')
)
from bokeh.models import DatetimeTickFormatter
from bokeh.plotting import show, figure, output_notebook
output_notebook()
p = figure(width=300, height=300, x_axis_type='datetime')
p.xaxis[0].formatter = DatetimeTickFormatter(days="%U", months="%m %U")
p.line(x='index', y='data', source=df)
show(p)
Upvotes: 0