Can I access the bokeh "plotting" low level interface from the "higher level charts" object?
I used the HeatMap example here to get the graph below http://docs.bokeh.org/en/0.11.0/docs/user_guide/charts.html#heatmap
Now I want:
1) Add x & y-axis labels
2) Reverse Y-axis range
3) Place the x-axis on top (not bottom)
Is this possible with the p handle in HeatMap?
If not, is it possible to return to the shape handle via p?
Code below:
from bokeh.charts import HeatMap, output_file, show
import pandas as pd
output_file('heatmap.html')
df = pd.DataFrame(
dict(apples=[4, 5, 8],
bananas=[1, 2, 4],
pears=[6, 5, 4]),
index=['2012', '2013', '2014'])
p = HeatMap(df, title='Fruits')
# 1) Want to label the axis
p.xlabel('This is a test label') # This does not appear
# 2) Want to reverse the Y axis: 2012:2014 to 2014:2012
p.y_range(start=2014, end=2012) # TypeError: 'FactorRange' object is not callable
# 3) Want to move the x axis (apples, bananas & pears) to the top, just under the title 'fruits'
# ?
show(p)
source to share
As far as I can tell, it is not possible to access the properties of a shape from a high level chart like HeatMap. If anyone else is wondering about this, instead of using HeatMap, here's what I did:
-
I had to create ColumnDataSource,
-
Define a color code,
-
Create a figure: p = figure (...)
-
Then use the rect method, create each block separately with the corresponding color from the color map
An example of this approach: http://bokeh.pydata.org/en/latest/docs/tutorials/solutions/gallery/unemployment.html
After that, 3 things I wanted to do were possible:
1) Add x and y axis labels
p.xaxis.axis_label = 'my X label'
p.yaxis.axis_label = 'my y label'
2) Cancel the y-axis range
if y_names is the list of y categories:
p = figure(...., y_range=list(reversed(y_names), ...)
3) Place the x-axis at the top (not at the bottom)
p = figure(..., x_axis_location="above", ...)
It's not pretty, but it works.
source to share