python - 绘图中缺少显示的标题

标签 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", colors="#182844", layout=layout)

最佳答案

最好使用 go.Figure() 而不是 iplot()。很难弄清楚你的 plotly 有什么问题,但以 plot.ly/python/horizontal-bar-charts/ 为例您可以使用 fig.update_layout()

轻松设置标题和背景颜色

plotly :

enter image description here

代码:

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

关于python - 绘图中缺少显示的标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58228675/

相关文章:

python - Flask应用程序部署: Internal Server Error

python - Python 中 AndAlso (&&) 和 OrElse (||) 逻辑运算符的等效项是什么?

java - 如何设置 "JOptionPane.showMessageDialog"的位置

python - Plotly:两行子图中的刻度标签问题

python - 计算 Pandas 数据框中单词的频率

python - 用子进程包装 cmd.exe

html - HTML 中两个面板布局的容器高度

带有布局的 Android 轮播效果

javascript - JS Plotly 奇数边距顶部

r - 一行中的多个绘图饼图