Plotly in Python:如何在使用matplotlib时添加图例?

时间:2016-09-13 06:38:15

标签: python matplotlib plotly

在情节中,您可以将matplotlib图转换为plot.ly:

X = [1,2,3] Y = [4,5,6] plt.plot(X,Y,标记='测试') 无花果= plt.gcf()

enter image description here

但是,如果我添加图例,

x=[1,2,3]
y=[4,5,6]
plt.plot(x,y,label='test')
fig=plt.gcf()
plt.legend()

它将返回错误RuntimeError: Cannot get window extent w/o renderer

我想知道这是什么问题? plot.ly是否支持使用matplotlib制作的图例?

1 个答案:

答案 0 :(得分:0)

showlegend=True添加到plt.plot(x,y,label='test')可以解决问题。