Plotly express标题样式

2024-04-29 04:54:55 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经挣扎了几个小时来设计我的饼图标题。本质上,我想增加字体大小并使其加粗。无论是从对象参数还是从update_layout我都没有找到正确的方法来处理这个问题

还有没有办法增加标签的大小并删除图例

非常感谢您的支持

这是我的密码:

pie_chart = px.pie(
    data_frame=ca_sum_df,
    values='Last month sales',
    names='Commercial network',
    color='Commercial network',
    #color_discrete_sequence=["red","green"],
    color_discrete_map={'VIP customers':"#d28c00","Standard Retail Partner":'#d9d9d9'},
    hover_data=['Commercial network','Last month sales'],
    title="TURNOVER SPLIT-DOWN",
    template='ggplot2',
    width=800,
    height=600,
    hole=0.5

)
pie_chart.update_layout(
    # Add annotations in the center of the donut pies.
    annotations=[dict(text=val_ca_sum, x=0.50, y=0.5, font_size=30, showarrow=False)],
    font=dict(size=25)
)

pie_chart.write_image("images/Page1_TurnoverSplitDown.png")

Tags: datachartupdatenetworkcacolorannotationslast
1条回答
网友
1楼 · 发布于 2024-04-29 04:54:55

字体大小可以通过更改

pie_chart.update_layout(title={'font': {'size': 50}})

要使标题加粗,请使用HTML语法<b></b>

pie_chart.update_layout(title={'text': '<b>TURNOVER SPLIT-DOWN</b>'})

标签的大小可以通过以下方式更改:

pie_chart.update_layout(font={'size': 30})

并且可以使用删除图例

pie_chart.update_layout(showlegend=False)

您可以通过编写以下命令将所有修改合并到一个调用中:

pie_chart.update_layout(
    showlegend=False,
    font={'size': 30},
    title={'text': '<b>TURNOVER SPLIT-DOWN</b>', 'font': {'size': 50}}
)

相关问题 更多 >