Python 我可以进入较低级别的bokeh';绘图';来自更高级别的接口';图表';对象

Python 我可以进入较低级别的bokeh';绘图';来自更高级别的接口';图表';对象,python,charts,bokeh,Python,Charts,Bokeh,维护人员注意:这个问题指的是过时的bokeh.chartsAPI,它已经不存在了。有关分类热图的最新信息,请参阅: 过时: 我使用这里的热图示例生成了下面的图表 现在我想: 1)添加x轴和y轴标签 2)反转y轴的范围 p.xaxis.axis_label = 'my X label' p.yaxis.axis_label = 'my y label' if y_names is the list of y categories: p = figure(...., y_range=

维护人员注意:这个问题指的是过时的
bokeh.charts
API,它已经不存在了。有关分类热图的最新信息,请参阅:



过时:

我使用这里的热图示例生成了下面的图表

现在我想:

1)添加x轴和y轴标签

2)反转y轴的范围

p.xaxis.axis_label = 'my X label'

p.yaxis.axis_label = 'my y label'
if y_names is the list of y categories:

p = figure(...., y_range=list(reversed(y_names), ...)
3)将x轴放在顶部(而不是底部)

这些是否可以通过加热图的手柄p实现

如果没有,是否可以通过p返回图形句柄

代码剪辑如下:

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)

据我所知,不可能从像热图这样的高级图表访问地物属性。如果其他人对此感到疑惑,请不要使用热图,以下是我所做的:

  • 我必须创建一个ColumnDataSource

  • 定义一个颜色映射

  • 创建地物:p=地物(…)

  • 然后使用rect方法使用colormap中的适当颜色分别创建每个块

  • 在那之后,我想做的三件事是可能的:

    1)添加x轴和y轴标签

    p.xaxis.axis_label = 'my X label'
    
    p.yaxis.axis_label = 'my y label'
    
    if y_names is the list of y categories:
    
    p = figure(...., y_range=list(reversed(y_names), ...)
    
    2)反转y轴的范围

    p.xaxis.axis_label = 'my X label'
    
    p.yaxis.axis_label = 'my y label'
    
    if y_names is the list of y categories:
    
    p = figure(...., y_range=list(reversed(y_names), ...)
    
    3)将x轴放在顶部(而不是底部)

    这并不漂亮,但很管用