Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you get the range of the x-axis of a Plotly graph?

I'm trying to retrieve the range of the x-axis when you zoom in a plotly scatter plot, but when I tried to access it using: figure['layout']['xaxis']['range'] it just returns 'None'.

This is the code that I am using to create the graph:

# self.plot contains the dataframe passed to the function to be plotted
self.plot = df
# Creates the plotly plot figure
self.fig = self.plot.iplot(asFigure=True,kind='scatter', xTitle='Date', yTitle='Temperature')
# Displays the plot
iplot(self.fig, show_link=False)

I'm using cufflinks to create the plot from a pandas DataFrame so I don't explicitly set the layout.xaxis.range to anything. Also I'm using a Jupyter Notebook to display the graph, if that helps at all. So is there any way of getting the range of the x-axis of the current view window of the plot? Thanks in advance!

like image 852
Thao-Tran Le-Phuong Avatar asked Jun 17 '16 15:06

Thao-Tran Le-Phuong


1 Answers

That does not seem to be possible at the moment using python. There's a post on community.plot.ly that says:

Graph parameters don’t dynamically change with chart actions. However, as you zoom, the plot does emit data regarding the new x-axis range, you’re unable to to access this information directly in Python. Instead you’d have to use javascript: https://plot.ly/javascript/zoom-events/

like image 104
vestland Avatar answered Oct 15 '22 09:10

vestland