【问题标题】:Altair: How do I change the font size of the column title in a grouped bar chart?Altair:如何更改分组条形图中列标题的字体大小?
【发布时间】:2020-06-08 07:13:02
【问题描述】:

所以我有这个数据框:

df = pd.DataFrame([['Cat', 3, 'F', 'red'], 
                   ['Dog', 5, 'F', 'blue'], 
                   ['Cat', 4, 'M', 'red'], 
                   ['Dog', 6, 'M', 'blue']], 
                  columns=['Pet', 'Age', 'Gender', 'color'])

然后我尝试用这段代码将其可视化

chart = alt.Chart(df).mark_bar(size = 60).encode(
   column='Pet',
   x = "Gender",
   y = "Age",
   color=alt.Color('color', scale=None),
).properties(
    width=125,
    height=300,
).configure_title().configure_axis(
    labelFontSize = 12,
    titleFontSize = 14
)
chart

我想增加列标题的大小(我认为这是名称?)“宠物”更大。我该怎么做?

【问题讨论】:

    标签: python pandas jupyter-notebook altair


    【解决方案1】:

    列标题属性可以通过column编码的header属性进行调整;例如:

    column=alt.Column('Pet', header=alt.Header(titleFontSize=20))
    

    您可以在alt.Header documentation 中阅读有关所有可用属性的信息。

    【讨论】:

    • 非常感谢!
    猜你喜欢
    • 1970-01-01
    • 2019-09-05
    • 2019-03-18
    • 2019-10-09
    • 2017-12-14
    • 1970-01-01
    • 2017-12-15
    • 2013-11-17
    • 1970-01-01
    相关资源
    最近更新 更多