我希望能够在下面的代码中为图例添加标题。然而,看看docs,我认为没有一种方法可以实现这一点。
import plotly.plotly as py
import plotly.graph_objs as go
trace0 = go.Scatter(
x=[1, 2, 3, 4, 5],
y=[1, 2, 3, 4, 5],
)
trace1 = go.Scatter(
x=[1, 2, 3, 4, 5],
y=[5, 4, 3, 2, 1],
)
data = [trace0, trace1]
fig = go.Figure(data=data)
py.iplot(fig, filename='default-legend')
我以前做过这样的工作,减少了数据跟踪
只是在已经提出的解决方案中添加了一些属性
name
name
属性有助于将自定义名称添加到定义的图例中。更新:
若要不定义图例但具有批注定位属性,请使用以下代码。
注意:
您需要为使用此方法的注释和各种图例定义
x
和y
位置。您可以在
text
属性中使用html(例如:text='Legend Title<br>kinda lengthy',
)上一次尝试:
另一种方法是创建图例并使用注释将标题添加到图例中。如果不在可编辑模式下使用图形。因此在下面的例子中,图例设置为x=0和y=1,因为我希望图例标题位于实际图例之上,所以我将注释位置设置为x=0,y=1.5。x-ref和y-ref需要设置为paper。这将给出一个很好的注释,比如
代码:
相关问题 更多 >
编程相关推荐