简体   繁体   English

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

[英]Python Plotly, how to remove background horizontal line?

How to get rid of the background horizontal lines on this chart?如何摆脱此图表上的背景水平线? The lines that represent the scales 5, 10, 15, etc. You can find the code below:代表刻度 5、10、15 等的线条。您可以在下面找到代码:

在此处输入图像描述

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

Thanks!谢谢!

Enlightening examples can be found at https://plot.ly/python/axes/启发性的例子可以在https://plot.ly/python/axes/找到

Simply add showgrid=False to your yaxis and xaxis dictionaries.只需将showgrid=False添加到您的yaxisxaxis字典中。

All the dict options for your xaxis can be found at https://plot.ly/python/reference/#layout-xaxis (and the yaxis is similarly at https://plot.ly/python/reference/#layout-yaxis )您的 xaxis 的所有 dict 选项都可以在https://plot.ly/python/reference/#layout-xaxis找到(yaxis 也同样在https://plot.ly/python/reference/#layout-yaxis )

we can update layout using fig.update_layout()<\/code> method by setting showgrid = False<\/code> for both xaxis<\/code> and yaxis<\/code> parameters.我们可以更新布局使用fig.update_layout()<\/code>方法通过设置showgrid = False<\/code>两个xaxis<\/code>和yaxis<\/code>的参数。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM