Python bokeh figure quad categorical x-axis does not plot if strings present -
i have dataframe 2 columns: x_att1
, y_att1
. y_att1
contains int or float. if x_att1
contains numbers string can plot y_att1
. if x_att1
contains strings nothing plotted. don't know why. bug or feature? use bokeh 0.10.0
code 1 numbers string @ x_att1
(works):
from bokeh.plotting import figure, output_file, show bokeh.models import linearaxis, range1d import pandas pd output_file("bars.html") df = pd.dataframe() df['y_att1'] = [0.70,0.68,0.50,0.48,0.30,0.28] df['x_att1'] = ['0','4','2','7','3','1'] p = figure(title="twin y-axis bar example", x_range=df['x_att1'].values.tolist()) p.quad(bottom=0, top=df['y_att1'], left=df['x_att1'].values.tolist() , right=df['x_att1'].values.tolist(), line_width=7, line_color='red') p.yaxis.axis_label = 'left y axis' p.yaxis.axis_label_text_color = 'red' p.xaxis.axis_label = 'x axis' p.xaxis.axis_label_standoff = -5 show(p)
code 2 strings @ x_att1
(does not work):
from bokeh.plotting import figure, output_file, show bokeh.models import linearaxis, range1d import pandas pd output_file("bars.html") df = pd.dataframe() df['y_att1'] = [0.70,0.68,0.50,0.48,0.30,0.28] df['x_att1'] = ['b','d','a','h','f','e'] #changed line p = figure(title="twin y-axis bar example", x_range=df['x_att1'].values.tolist()) p.quad(bottom=0, top=df['y_att1'], left=df['x_att1'].values.tolist() , right=df['x_att1'].values.tolist(), line_width=7, line_color='red') p.yaxis.axis_label = 'left y axis' p.yaxis.axis_label_text_color = 'red' p.xaxis.axis_label = 'x axis' p.xaxis.axis_label_standoff = -5 show(p)
code 3 strings @ x_att1
, trick (works):
from bokeh.plotting import figure, output_file, show bokeh.models import linearaxis, range1d import pandas pd output_file("bars.html") df = pd.dataframe() df['y_att1'] = [0.70,0.68,0.50,0.48,0.30,0.28] df['x_att1'] = ['b','d','a','h','f','e'] p = figure(title="twin y-axis bar example", x_range=df['x_att1'].values.tolist()) p.quad(bottom=0, top=df['y_att1'], left=df['x_att1'].values.tolist() , right=df['x_att1'].values.tolist(), line_width=7, line_color='red') p.yaxis.axis_label = 'left y axis' p.yaxis.axis_label_text_color = 'red' #added these 2 lines p.y_range.start = 0 p.y_range.end = df['y_att1'].max()*1.1 p.xaxis.axis_label = 'x axis' p.xaxis.axis_label_standoff = -5 show(p)
nice day!
Comments
Post a Comment