【问题标题】:Bokeh: unable to show bar chart figure when x axis label is vertical散景:当 x 轴标签垂直时无法显示条形图
【发布时间】:2021-08-20 15:52:07
【问题描述】:

我不知道为什么,当我尝试将 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

【问题讨论】:

  • 我试图运行您的代码进行调查,结果发现它依赖于外部数据。请更新您的问题以获得完整、独立的Minimal Reproducible Example
  • 我要显示的变量名称太长,我删除了绘图的高度限制 (plot_height=250),它现在可以工作了。
  • 很高兴您发现了问题!请自行回答以帮助保持散景整洁。

标签: python bar-chart bokeh


【解决方案1】:

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

  • 移除高度
  • 增加高度

【讨论】:

    猜你喜欢
    • 2021-12-03
    • 2019-01-17
    • 1970-01-01
    • 1970-01-01
    • 2014-07-30
    • 2019-07-15
    • 2021-06-01
    • 2018-07-24
    • 2013-06-21
    相关资源
    最近更新 更多