2

I'm trying to figure out how to control the layout of plotly generated graphs using cufflinks. For example: This code will generate a graph with the yaxis lables on the left side. How can I move the Y axis labels to the other side of the graph?

import pandas as pd
import cufflinks as cf
cf.go_offline()
from plotly.offline import download_plotlyjs, plot,iplot

df.iplot(kind='scatter',mode='lines+markers',x='Time',title='Events over Time',
                       y='Events',margin={'l':450})   

I searched on the web for a while, so here I am :).

Plotly APIs are here: https://plot.ly/python/reference/#layout-yaxis-side

I'm having trouble figuring out how to apply this one though:

side ( enumerated : "top" | "bottom" | "left" | "right" )

Determines whether a x (y) axis is positioned at the "bottom" ("left") or "top" ("right") of the plotting area.

2 Answers 2

3

You can return the entire figure using the asFigure=True attribute of the iplot method. Once you have the figure you can update the underlying plotly layout accordingly.

_data = df.iplot(kind='scatter', mode='lines+markers',
                 x='Time', y='Events', 
                 title='Events over Time', asFigure=True)
_data['layout']['yaxis'] = dict(side='left')
_data.iplot()
Sign up to request clarification or add additional context in comments.

Comments

0

You can pass a layout argument to the iplot function to set it directly in iplot. Note that this will overwrite all the layout options that were passed directly as kwarg to iplot() method, for example title arg.

If you want to keep it you have to pass it to the layout dictionary too

import cufflinks as cf 

cf.go_offline()

df = cf.datagen.lines(2, columns=['Time', 'Events'])
title = 'Events over Time'
layout = dict(yaxis=dict(side='left'),
                  title=title)

df.iplot(kind='scatter',mode='lines+markers',x='Time', y='Events', layout=layout) 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.