Search code examples
pythonbar-chartbokeh

Bokeh: unable to show bar chart figure when x axis label is vertical


I don't know why, when I try to change x axis label orientation to "vertical", the output file show is blank while it worked perfectly before:

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)

This line is problematic:

p.xaxis.major_label_orientation = "vertical"

Same thing with this alternative code:

p.xaxis.major_label_orientation = math.pi/2

Solution

  • I've resolved my problem. My figure was not showing because I configure a plot height and it was too little (plot_height=250). If you have the same problem, two choices:

    • remove the height
    • increase the height