Search code examples
pythonpandasbar-chartbokeh

bokeh error FactorRange must specify a unique list of categorical factors for an axis: duplicate factors found: 'M. Laxmikanth'


My data looks like this

data.iloc[:,1]

41                         Barack Obama
95                 Muthuvenkatachalam S
16                        M. Laxmikanth
21                         R S Aggarwal
32                        R.S. Aggarwal
58                  MTG Editorial Board
7                           James Clear
54                         Ramesh Singh
70                      Nitin Singhania
88                        M. Laxmikanth
81    Think Tank of Kiran Institute of…
99                               Solimo
2                    Wonder House Books
39                         Navdeep Kaur
33                          Jeff Kinney
Name: Author, dtype: object

We can see both 16 and 88 are the same, which is M. Laxmikant

p = figure(x_range=data.iloc[:,1], plot_width=800, plot_height=550, title="Authors Highest Priced Book", toolbar_location=None, tools="")
p.vbar(x=data.iloc[:,1], top=data.iloc[:,4], width=0.9)
p.xgrid.grid_line_color = None
p.y_range.start = 0
p.xaxis.major_label_orientation = math.pi/2
show(p)

I have imported all the necessary libraries. This gives me the error

ERROR:bokeh.core.validation.check:E-1019 (DUPLICATE_FACTORS): FactorRange must specify a unique list of categorical factors for an axis: duplicate factors found: 'M. Laxmikanth'

How could I fix it?


Solution

  • You need to reduce data.iloc[:,1] to a unique set of values and then order them in the order you want them to appear on the axis. A common way to unique a sequence in Python is to pass it to set.