Python Plotly,如何去除背景水平线?

问题描述 投票:0回答:2

如何去掉图表上的背景水平线?代表音阶 5、10、15 等的线条。您可以在下面找到代码:

enter image description here

# Plotting waterfall chart for Years of Experience lost on DA Team

x_data = ['A', 'B', 'C', 'D', 'E']
y_data = [13, 23.5, 17.5, 10, 2.5] # y_data for positioning the annotations
text = ['27', '7', '5', '10', '5']

# Base
Base = go.Bar(x=x_data, y=[0, 20, 15, 5, 0], marker=dict(color='rgba(1,1,1,     0.0)',))
# Total
Total = go.Bar(x=x_data, y=[27, 0, 0, 0, 0],     marker=dict(color='#003A6F',line=dict(color='k',width=1,)))
# Individuals
Individuals = go.Bar(x=x_data, y=[0, 7, 5, 10, 0], marker=dict( color='#FFE512',line=dict(color='k',width=1,)))
# Years of Experience Left
Years_left = go.Bar(x=x_data, y=[0, 0, 0, 0, 5],  marker=dict(color='00AB39',line=dict(color='k',width=1,)))

# Put all traces in one "data" list
data = [Base, Total, Individuals, Years_left]

# Layout takes care of things like chart title, x and y axis titles and font     sizes, etc.
layout = go.Layout(
    title='Chart One',
    barmode='stack',
    yaxis=dict(title='Number of Years', titlefont=dict(size=yaxis_font_size)
                              , tickfont=dict(size=yaxis_font_size)),
    xaxis=dict(title='Names', titlefont=dict(size=xaxis_font_size)
                              , tickfont=dict(size=yaxis_font_size)) ,   
    showlegend=False
)

annotations = []
annotations_colors = ['rgba(245, 246, 249, 1)', 'k', 'k', 'k', 'rgba(245,     246, 249, 1)'] # assign colors to annotations
for i in range(0, 5):
    annotations.append(dict(x=x_data[i], y=y_data[i], text=text[i],     font=dict(family='Arial', size=14, color=annotations_colors[i]),     showarrow=False,))
    layout['annotations'] = annotations

fig = go.Figure(data=data, layout=layout) # Standard plotly way to assign     data and layout
iplot(fig, filename='Chart One')
python formatting plotly
2个回答
26
投票

可以在以下位置找到启发性示例:https://plot.ly/python/axes/

只需将

showgrid=False
添加到您的
yaxis
xaxis
词典即可。

xaxis 的所有 dict 选项都可以在 https://plot.ly/python/reference/#layout-xaxis 找到(yaxis 也类似在 https://plot.ly/python/reference/ #layout-yaxis


8
投票

我们可以使用

fig.update_layout()
方法更新布局 通过为
showgrid = False
xaxis
参数设置
yaxis

fig.update_layout(xaxis=dict(showgrid=False),
              yaxis=dict(showgrid=False)
)

我们可以直接使用

fig.update_xaxes()
fig.update_yaxes()
方法并赋值
showgrid=False

fig.update_xaxes(showgrid=False)
fig.update_yaxes(showgrid=False)
© www.soinside.com 2019 - 2024. All rights reserved.