Bokeh: No plot when x values is non-numeric

Created on 26 Dec 2019  路  3Comments  路  Source: bokeh/bokeh

from bokeh.plotting import figure, output_file, show

plot = figure(plot_width=300, plot_height=300)
plot.vbar(x=[1, 2, 3], width=0.5, bottom=0, top=[1,2,3], color="#CAB2D6")

show(plot)

In the 3rd line of code, if x is stringlist like x= ['A','B','C'] then the plot does not show. X values does not have to be numeric in all case of graph plot like the vbar and hbar.

referred discussion

Most helpful comment

@taiwotman I'm not sure why you call that a workaround. Passing the list of categories as the range is a necessary step for handling categorical data in Bokeh. There are lots of examples in the docs:

https://docs.bokeh.org/en/latest/docs/user_guide/categorical.html

All 3 comments

@taiwotman in the future, for support/usage questions such as this, the Project Discourse is the best place to post:

https://discourse.bokeh.org/

Thanks @bryevdv for the recommendation. I guess fewer lines of code would help compare to this workaround.

from bokeh.plotting  import figure
from bokeh.embed import components
import numpy as np

def make_plot():
  label = ['A', 'B', 'C']
  y = [10, 5, 18]
  plot = figure(x_range=label,y_range=(0,max(y)),plot_width=500,plot_height=300,title="x vs y")
               plot.xaxis.major_label_orientation = np.pi/4
               plot.vbar(label, top=y, width=0.5, color="#CAB2D6")

  script, div = components(plot)

  return script, div

plots = []
plots.append(make_plot())

@taiwotman I'm not sure why you call that a workaround. Passing the list of categories as the range is a necessary step for handling categorical data in Bokeh. There are lots of examples in the docs:

https://docs.bokeh.org/en/latest/docs/user_guide/categorical.html

Was this page helpful?
0 / 5 - 0 ratings