散景 x 轴 xticks 旋转?

bokeh x-axis xticks rotation?

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)

在 pandas 中处理散景,但 x 轴上的所有日期都重叠。我如何调整我的代码以在 x 轴上垂直旋转日期?

您需要先在 x 轴上创建一个轴元素。 之后可以用major_label_orientation的方法进行π/2的旋转。下面是一个例子:

p.xaxis.major_label_orientation = math.pi/2

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

我知道这个多亏了这个帖子: