简体   繁体   中英

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!

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/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM