Python 打印中显示的标题缺失

Python 打印中显示的标题缺失,python,layout,plotly,Python,Layout,Plotly,我试图更改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", col

我试图更改
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)

你最好使用
go.Figure()
而不是
iplot()
。很难弄清楚你的绘图有什么问题,但是通过一个例子,你可以使用
fig.update\u layout()

绘图:

import plotly.graph_objects as go

fig = go.Figure(go.Bar(
            x=[20, 14, 23],
            y=['giraffes', 'orangutans', 'monkeys'],
            orientation='h'))

fig.update_layout(title='Title',
                 paper_bgcolor='rgba(0,0,0,0)',
                 plot_bgcolor='rgba(0,0,0,0)')

fig.show()

代码:

import plotly.graph_objects as go

fig = go.Figure(go.Bar(
            x=[20, 14, 23],
            y=['giraffes', 'orangutans', 'monkeys'],
            orientation='h'))

fig.update_layout(title='Title',
                 paper_bgcolor='rgba(0,0,0,0)',
                 plot_bgcolor='rgba(0,0,0,0)')

fig.show()

您最好使用
go.Figure()
而不是
iplot()
。很难弄清楚你的绘图有什么问题,但是通过一个例子,你可以使用
fig.update\u layout()

绘图:

import plotly.graph_objects as go

fig = go.Figure(go.Bar(
            x=[20, 14, 23],
            y=['giraffes', 'orangutans', 'monkeys'],
            orientation='h'))

fig.update_layout(title='Title',
                 paper_bgcolor='rgba(0,0,0,0)',
                 plot_bgcolor='rgba(0,0,0,0)')

fig.show()

代码:

import plotly.graph_objects as go

fig = go.Figure(go.Bar(
            x=[20, 14, 23],
            y=['giraffes', 'orangutans', 'monkeys'],
            orientation='h'))

fig.update_layout(title='Title',
                 paper_bgcolor='rgba(0,0,0,0)',
                 plot_bgcolor='rgba(0,0,0,0)')

fig.show()

我尝试将布局添加到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)))

我尝试将布局添加到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)))

我的建议对你有何影响?@vestland我尝试将布局添加到iplot本身,结果成功了。我们也可以同时调整边距。示例代码:data['Region'].value\u counts()[1:10][::-1].iplot(kind=“barh”,bargap=.5,title=“面临恐怖袭击的前十大城市”,colors=“mediumruch”,layout=layout(paper\u bgcolor='rgba(0,0,0)'图(rgba(0,0,0),宽800,高500,标题"十大恐怖袭击地区")酷!请考虑把它当作答案而不是评论!我的建议对你有什么影响?@vestland我试着在iplot中添加布局,结果成功了。我们也可以同时调整边距。示例代码:data['Region'].value\u counts()[1:10][::-1].iplot(kind=“barh”,bargap=.5,title=“面临恐怖袭击的前十大城市”,colors=“mediumruch”,layout=layout(paper\u bgcolor='rgba(0,0,0)'图(rgba(0,0,0),宽800,高500,标题"十大恐怖袭击地区")酷!请考虑把它当作答案而不是评论!