首页 > 解决方案 > 缺少标题显示在情节中

问题描述

我正在尝试更改背景颜色plotly,但在使用布局功能后,我从 plotly 中丢失了标题。

layout = Layout(
    paper_bgcolor='rgba(0,0,0,0)',
    plot_bgcolor='rgba(0,0,0,0)'
)
data['Country'].value_counts()[:10][::-1].iplot(kind="barh",bargap=.5, title="Top 10 countries faced terrorist attacks", colors="#182844", layout=layout)

标签: pythonlayoutplotly

解决方案


我尝试为 iplot 本身添加布局并且它有效。我们也可以随之调整边距。

示例代码:

data['Nationality'].value_counts()[0:10][::-1].iplot(kind="barh",bargap=.5, 
                                                colors="mediumorchid", layout=Layout(paper_bgcolor='rgba(0,0,0,0)',
                                                                             plot_bgcolor='rgba(0,0,0,0)',
                                                                                width=800, height=500, 
                                                                                title='Nationality of terrorist attacks',
                                                                                margin=dict(l=200, r=50, t=80, b=50)))

在此处输入图像描述


推荐阅读