matplotlib后端具有不同的元素大小

时间:2018-11-02 23:08:15

标签: holoviews

我正在尝试完成热图颜色栏,以在我的热图中添加有关kdims的额外信息。 (如果您熟悉R的colSideColors包,则类似于heatmap.2选项。)

使用bokeh后端可以获得不错的结果,但是不知道如何在使用matplotlib后端时获得自定义(不同)的元素大小。

谁能告诉我如何在matplotlib后端示例中使条形图“更短”(少“高”)?

设置

import pandas as pd
import numpy as np
import holoviews as hv
hv.extension('bokeh', 'matplotlib')

# dummy data
samples = ['sample{}'.format(x) for x in range(5)]
df = pd.DataFrame(np.random.rand(5, 5),columns=samples, index=samples).reset_index()
df = df.melt(id_vars='index', var_name='y').rename(columns={'index': 'x'})

# column means
df_strip = df.groupby('x').mean().reset_index()
df_strip['y'] = 'dummy'

# make plots
heatmap = hv.HeatMap(df, kdims=['x','y'])
strip = hv.HeatMap(df_strip, kdims=['x','y'])

散景的结果

%%output size=100 backend='bokeh'
(strip.options(xaxis=None, yaxis=None, height=50) + 
 heatmap.options(xrotation=90)).cols(1)

enter image description here

使用matplotlib后端的结果

%%output size=100 backend='matplotlib'
%%opts Layout [sublabel_format='' vspace=0.1]

(strip.options(xaxis=None, yaxis=None, aspect=1) + 
 heatmap.options(xrotation=90, aspect=1)).cols(1)

enter image description here

hv.__version__
'1.10.8'

1 个答案:

答案 0 :(得分:1)

不幸的是,在两个后端中,大小调整的工作方式非常不同,这意味着要获得相同的行为可能有些困难。在这种特殊情况下,您将要在带状图上设置较大的外观,同时还告诉布局在计算图的大小时应权衡外观。这样做看起来像这样:

%%output size=100 backend='matplotlib'
%%opts Layout [sublabel_format='' vspace=0.1 aspect_weight=1]
(strip.options(xaxis=None, yaxis=None, aspect=5) + 
 heatmap.options(xrotation=90, aspect=1)).cols(1)

enter image description here

相关问题