[英]How to remove 'Aa' from the legend in Plotly.py?
How to remove 'Aa' from the legend?如何从图例中删除“Aa”?
The code below is from the example on this page under Adding Text to Data in Line and Scatter Plots : https://plotly.com/python/text-and-annotations/下面的代码来自此页面上的示例,在在线图和散点图中添加文本到数据: https://plotly.com/python/text-and-annotations/
import plotly.graph_objects as go
fig = go.Figure()
fig.add_trace(go.Scatter(
x=[0, 1, 2],
y=[1, 1, 1],
mode="lines+markers+text",
name="Lines, Markers and Text",
text=["Text A", "Text B", "Text C"],
textposition="top center"
))
fig.add_trace(go.Scatter(
x=[0, 1, 2],
y=[2, 2, 2],
mode="markers+text",
name="Markers and Text",
text=["Text D", "Text E", "Text F"],
textposition="bottom center"
))
fig.add_trace(go.Scatter(
x=[0, 1, 2],
y=[3, 3, 3],
mode="lines+text",
name="Lines and Text",
text=["Text G", "Text H", "Text I"],
textposition="bottom center"
))
fig.show()
Edit: I would like to keep the text in the markers.
编辑:我想将文本保留在标记中。
Thanks谢谢
The advanced solution is to customize the CSS before calling fig.show()
:高级解决方案是在调用
fig.show()
之前自定义 CSS :
from IPython.core.display import HTML
HTML("""
<style>
g.pointtext {display: none;}
</style>
""")
fig.show()
This results in the desired behavior.这会产生所需的行为。
The 'Aa' is the result of the existence of text in the markers. 'Aa' 是标记中存在文本的结果。 If you remove text and leave just markers and lines, the 'Aa' disappears.
如果您删除文本并只留下标记和线条,“Aa”就会消失。
For example:例如:
fig.add_trace(go.Scatter(
x=[0, 1, 2],
y=[1, 1, 1],
# mode="lines+markers+text", # comment out
mode="lines+markers", # new code
name="Lines, Markers and Text",
text=["Text A", "Text B", "Text C"],
textposition="top center"
))
You can add the current latest plotly cdn可以添加当前最新的plotly cdn
<script src="https://cdn.plot.ly/plotly-2.8.3.min.js"></script>
'Aa' will disappear 'Aa' 会消失
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.