Retrieving the range of the x-axis of a zoomed in plot

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!

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/

1 Like

Is this still up-to-date information, is it possible to access x-axis range within python (maybe though some interpreter of JS)?

Hi @davzup89, there is a way to do this in python, it’s not recommended though:

Thanks. Just being curious, for which reasons it is not recommended? Overload due to user activity?

@davzup89 I actually don’t know, that’s just the warning message you get while using it. :rofl:

Might be interesting to know, though. @adamschroeder

hey @davzup89 hi @AIMPED

The issue with full_figure_for_development() is that it spins up Kaleido from Python; basically it’s running a whole browser on the server to render the figure, which is very resource-hungry in terms of RAM, CPU, boot-time, etc.

So it’s very much not recommended for production, hence the name for_development. in the comment, the figure is already being rendered in a browser in a Dash app, so you can use the client’s browser and a client-side callback to grab the relevant info if you like. It much cheaper, resource-wise.

2 Likes