简体   繁体   English

删除标题 plotly python

[英]remove titles plotly python

How can I remove the titles in the following pic?如何删除下图中的标题?

I would like to remove top axis titles since they are redundant and too long for the pic.我想删除顶轴标题,因为它们是多余的并且对于图片来说太长了。

在此处输入图像描述

This is the code I am using:这是我正在使用的代码:

import plotly.express as px

fig = px.box(DF.melt(), y="value", facet_col="variable", boxmode="overlay", color="variable")
fig.update_yaxes(matches=None)

for i in range(len(fig["data"])):
    yaxis_name = 'yaxis' if i == 0 else f'yaxis{i + 1}'
    fig.layout[yaxis_name].showticklabels = True
    #fig.update_layout(showlegend=False)


fig.update_layout(legend = dict(bgcolor = 'white'))
fig.update_layout(plot_bgcolor='white')

fig.update_xaxes(showline=True, linewidth=2, linecolor='black')#, mirror=True)
fig.update_yaxes(showline=True, linewidth=2, linecolor='black')#, mirror=True)

fig.update_xaxes(showgrid=True, gridwidth=1, gridcolor='gray')
fig.update_yaxes(showgrid=True, gridwidth=1, gridcolor='gray')

fig.show()

You will have to iterate over the labels to update the text to empty " ".您将不得不遍历标签以将文本更新为空“”。 Include this in your code:将此包含在您的代码中:

fig.for_each_annotation(lambda a: a.update(text=""))

Here is a similar question responded这是一个类似的问题回答

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

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