0

image of plot updated plot image(still looks off)

source = ColumnDataSource(data=dict(dt=df['Date/Time'],
                                       temp=df['Temp (C)'],
                                       dew=df['Dew Point Temp (C)']))
    
p=figure(x_range=df['Date/Time'],
        title='Temperature across the year',
        x_axis_label='Date and Time',
        y_axis_label='Temperature in C',
        sizing_mode='stretch_width',
        plot_height=300)
p.xaxis.major_label_orientation = "vertical"


p.line(x='dt',
      y='temp',
      source=source,
      legend_label='Temp C')

p.line(x='dt',
      y='dew',
      source=source,
      legend_label='Dew Point Temp C',
      color='red')

p.add_tools(HoverTool(tooltips=[('Temperature','@temp'),('Dew Temp','@dew'),('date','@dt')]))

show(p)

working on bokeh in pandas, but all the dates on the x axis are overlapping. how can i adjust my code to rotate the dates vertically on the xaxis?

1 Answers1

2

You need to create an axis element on your x axis first. Afterwards, you can use the major_label_orientation method to perform a rotation of π/2. An example below:

p.xaxis.major_label_orientation = math.pi/2

# or alternatively:
p.xaxis.major_label_orientation = "vertical"

I know this thanks to this thread : How to rotate X-axis labels in bokeh figure?