首页 > 解决方案 > 散景:当 x 轴标签垂直时无法显示条形图

问题描述

我不知道为什么,当我尝试将 x 轴标签方向更改为“垂直”时,输出文件显示为空白,而之前它运行良好:

import pandas as pd
from bokeh.io import show, output_file
from bokeh.plotting import figure
from bokeh.models import ColumnDataSource

output_file("average_conso_cpu.html")

average_cpu_data = pd.read_csv(r"average_cpu_hours.csv", sep=';')

filtered_data = average_cpu_data.head(10) 

source = ColumnDataSource(filtered_data)
payoffs = source.data['payoffname'].astype(str)
cpu_hours = source.data['avg_mc_cpu_hours']

p = figure(x_range=payoffs, plot_height=250, title="Payoffs")
p.left[0].formatter.use_scientific = False
p.vbar(x=payoffs, top=cpu_hours, width=0.9)

p.xaxis.major_label_orientation = "vertical"
p.xgrid.grid_line_color = None
p.y_range.start = 0

show(p)

这条线是有问题的:

p.xaxis.major_label_orientation = "vertical"

与此替代代码相同:

p.xaxis.major_label_orientation = math.pi/2

标签: pythonbar-chartbokeh

解决方案


我已经解决了我的问题。我的图没有显示,因为我配置了一个绘图高度并且它太小(plot_height=250)。如果你有同样的问题,有两种选择:

  • 去掉高度
  • 增加高度

推荐阅读