【问题标题】:Missing title displayed in plotly缺少标题显示在情节中
【发布时间】:2020-02-02 08:04:10
【问题描述】:

我正在尝试更改 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)

【问题讨论】:

  • 我的建议对你有什么效果?
  • @vestland 我尝试将布局添加到 iplot 本身并且它有效。我们也可以随之调整边距。
  • 示例代码:data['Region'].value_counts()[1:10][::-1].iplot(kind="barh",bargap=.5, title="Top 10 cities faced terrorist attacks", colors="mediumorchid", layout=Layout(paper_bgcolor='rgba(0,0,0,0)', plot_bgcolor='rgba(0,0,0,0)', width=800, height=500, title='Top 10 Region faced terrorist attacks'))
  • 酷!请考虑将其作为答案而不是评论!

标签: python layout plotly


【解决方案1】:

您最好使用go.Figure() 而不是iplot()。很难弄清楚你的情节有什么问题,但是通过plot.ly/python/horizontal-bar-charts/ 的示例,你可以使用fig.update_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()

【讨论】:

    【解决方案2】:

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

    示例代码:

    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)))
    

    enter image description here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-02-20
      • 2018-07-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-21
      • 1970-01-01
      • 2017-11-07
      相关资源
      最近更新 更多