具有 matplotlib 后端的不同元素大小
different element sizes with matplotlib backend
我正在尝试完成一个热图颜色条以在我的热图中添加关于 kdims 的额外信息。 (如果您熟悉 R 的 heatmap.2
包,就像 colSideColors
选项一样。)
我可以使用 bokeh 后端获得不错的结果,但不知道如何在使用 matplotlib 后端时获得自定义(不同)元素大小。
谁能告诉我如何在matplotlib后端示例中制作带状图"shorter"(less "high")?
设置
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)
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)
hv.__version__
'1.10.8'
不幸的是,大小调整在两个后端中的工作方式非常不同,这意味着获得相同的行为可能有些困难。在这种特殊情况下,您需要在带状图上设置更大的纵横比,同时告诉布局在计算图大小时应该对纵横比进行加权。这样做看起来像这样:
%%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)
我正在尝试完成一个热图颜色条以在我的热图中添加关于 kdims 的额外信息。 (如果您熟悉 R 的 heatmap.2
包,就像 colSideColors
选项一样。)
我可以使用 bokeh 后端获得不错的结果,但不知道如何在使用 matplotlib 后端时获得自定义(不同)元素大小。
谁能告诉我如何在matplotlib后端示例中制作带状图"shorter"(less "high")?
设置
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)
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)
hv.__version__
'1.10.8'
不幸的是,大小调整在两个后端中的工作方式非常不同,这意味着获得相同的行为可能有些困难。在这种特殊情况下,您需要在带状图上设置更大的纵横比,同时告诉布局在计算图大小时应该对纵横比进行加权。这样做看起来像这样:
%%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)