【问题标题】:Change fontsize in holoviews or hvplot在 holoviews 或 hvplot 中更改字体大小
【发布时间】:2019-11-27 12:51:00
【问题描述】:

如何使用 holoviews 或 hvplot 更改字体大小?

这是一个简单的情节示例:

# import libraries
import numpy as np
import pandas as pd

import holoviews as hv
import hvplot.pandas
hv.extension('bokeh', logo=False)

# create sample dataframe
df = pd.DataFrame({
    'col1': np.random.normal(size=30),
    'col2': np.random.normal(size=30),
})

# plot data with holoviews
my_plot = hv.Scatter(df, label='Scattering around')

【问题讨论】:

    标签: python holoviews hvplot holoviz


    【解决方案1】:

    1)您可以通过在绘图上使用 .opts(fontsize={}) 来更改字体大小,如下所示:

    # change fontsizes for different parts of plot
    my_plot.opts(fontsize={
        'title': 15, 
        'labels': 14, 
        'xticks': 10, 
        'yticks': 10,
    })
    


    2) 使用 version >= 1.13 of holoviews,您可以一次缩放所有字体,并使图例、标题、xticks 更大使用 .opts(fontscale=1.5)

    # make fonts all at once larger for your plot by the same scale
    # here I've chosen fontscale=2, which makes all fonts 200% larger
    my_plot.opts(fontscale=2)
    


    3)如果你想缩放你的字体并且你有一个全息图的散景后端,你可以这样做:

    # scale fontsizes with 200%
    my_plot.opts(fontsize={
        'title': '200%',
        'labels': '200%', 
        'ticks': '200%', 
    })
    

    有关可以更改字体大小的所有可能部分的更多信息,请参见此处:
    http://holoviews.org/user_guide/Customizing_Plots.html#Font-sizes

    【讨论】:

    • 这如何与 hvplot 一起使用?例如,df.hvplot.labels(x='A',y='B',text='C',size=4) 和 df.hvplot.labels(x='A',y='B ',text='C',fontsize={'labels':4}) 似乎对标签大小有任何影响。
    猜你喜欢
    • 2020-01-08
    • 2020-06-01
    • 1970-01-01
    • 2021-08-25
    • 1970-01-01
    • 1970-01-01
    • 2011-08-31
    • 2011-06-25
    • 1970-01-01
    相关资源
    最近更新 更多