2

I have a Excel sheet from which I am extracting the "TIME" and "TEMP" column using pandas library. 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 . Instead it just shows the last few characters of the "TIME" column which is the x-axis . Please help -

Python code -

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"

eExcel source file

The bokeh plot -

the bokeh plot

As you can see , the bokeh plot x-axis values are not completely plotted . Please help .

yacc
  • 2,915
  • 4
  • 19
  • 33
Boudhayan Dev
  • 85
  • 3
  • 12

1 Answers1

1

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).

If the format is correct, then you can control the x-ticks with the following:

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

bigreddot
  • 33,642
  • 5
  • 69
  • 122
pjw
  • 2,133
  • 3
  • 27
  • 44
  • 2
    At first, it seemed the `hourmin` keyword should specify how you want all the data show. It took me a bit to realize it actually is defining how you want just the `hourmin` zoom-level shown. So if you want it to use the same format as people zoom in/out, set the different zoom levels that would apply to your data to the same format, as in [this related post](https://stackoverflow.com/a/33873209/3585557). – Steven C. Howell Feb 14 '20 at 21:35
  • In 2021 (Holoviews v1.14.5) the proper format is: `curve.opts(xformatter=DatetimeTickFormatter(hourmin = ['%H:%M']))` per https://holoviews.org/user_guide/Customizing_Plots.html#Tick-formatters – Gifford N. Nov 23 '21 at 04:37