Reputation: 73
Is there an easy way to change the legend orientation when using plotly cufflinks? E.g for the code below:
df = pd.DataFrame(np.random.randn(1000, 2), columns=['A', 'B']).cumsum()
df.iplot(filename='cufflinks/line-example')
the legend appears on the right hand side of the graph. Is there an easy way to change it to the bottom without rewriting the layout dictionary?
For e.g. to create a secondary y-axis in cufflinks, I can just use:
df.iplot(secondary_y ='B')
without rewriting the layout dictionary.
Hope the above makes sense.
Upvotes: 1
Views: 1316
Reputation: 1435
No need to use asFigure
- you can pass the legend parameters directly as part of the layout object. In your example, it should look like this:
df = pd.DataFrame(np.random.randn(1000, 2), columns=['A', 'B']).cumsum()
df.iplot(filename='cufflinks/line-example', layout=dict(legend=dict(x=-1, y=0))) # places legend on the left rather than right
Upvotes: 1
Reputation: 4032
This should do what you're looking for. You can return the underlying Plotly figure from Cufflinks with asFigure=True
and access the legend position with my_fig.layout.legend=dict(x=-.1, y=.1)
.
You can adjust the x and y values as needed to move the legend.
df = pd.DataFrame(np.random.randn(1000, 2), columns=['A', 'B']).cumsum()
my_fig = df.iplot(asFigure=True)
my_fig.layout.legend=dict(x=-.1, y=.1)
my_fig.iplot(filename='line-example.html')
You can also see the values for the Plotly figure you create in a Jupyter Notebook with my_fig
.
Upvotes: 1