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!
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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With