I have this data:
data = {'Cities': {'Des_Moines': 80.0, 'Lubbock': -300.0, 'Minneapolis': 85.7,
'Orange_County': 80.0, 'Salt_Lake_City': 81.8, 'San_Diego': 80.0,
'San_Francisco': -400.0, 'Troy': -400.0, 'Wilmington': -300.0}}
I have plotted this using Seaborn
and it looks great.
df_data = pd.DataFrame(data).sort_values('Cities', ascending=False)
sns.barplot(x='Cities', y=df_data.index, data=df_data, label='Cities', palette='Greens')
However, I'll like to embed this is a Flask web app using Bokeh
.
I couldn't find an horizontal barplot
in Bokeh
. Even flipping the x
and y
axis do not seem to work. This is what I've done:
* Transposed df_data
from 9x1
to 1x9
. Yet, I'm still not getting anything remotely nice.
bar = Bar(df_data.transpose(), df_data.columns.tolist(), stacked=False, responsive=True)
script, div = components(bar)
Notice that I still do not have Horizontal
and my category
axis is messed up.
Can anyone help modify this further?
You can go for the low level and reconstruct an horizontal bar plot using rect or quad glyphs. The above code is tentative and lack cities labels on y axis (no more time now...). But I hope this can help.
It's pretty easy to do with rect glyphs. Note that when you set the y_range with categorical values, the indexing of these in the bokeh plot starts at 1. That's why the counter "j" starts at 1.
AFAIK there isn't one. This is the closest mention to it that I know of being #1856. For now only vertical bar charts are available:
Side Note: Transposing the data will work as you have tried, that is expected.
I think there is none. One hack could be to use a custom css with rotate() http://www.w3schools.com/css/css3_2dtransforms.asp