How to obtain generated x-axis and y-axis range in plotly plot?

Steven Cunden

I have a very simple bubble chart, see below. the only thing i need is to be able to get the range (or the min and max) or the x and y axis generated.

trace = go.Scatter(
    x=df_test['total_points_mean'],
    y=df_test['total_points_std'],
    mode='markers',
    text=df_test['play_maker'],
    marker=dict(size=df_test['week_nunique'],
                color = df_test['week_nunique'],
                showscale=True)
)

layout = go.Layout(title='Scatter Plot')
fig = go.Figure(data=[trace],layout=layout)

From the resulting plot, the min and max of the x axis seems to be around ~10 and ~29, but i need a way to generate the exact value of the axis range.

enter image description here

Is there a way to access the generated axes range?

jayveesea

Getting the axis range from a plotly plot is not possible within the python implementation. You can only retrieve the range if you specify the axis range in your layout (but then you really don't need it).

So if you try print(fig.layout.xaxis.range) you will get None.

If you need the limits then you'll need to make your own and apply it to the layout:

  1. get the min and max of the x-values: xmin, xmax
  2. pad these values with some factor: xlim = [xmin*.95, xmax*1.05]
  3. update the layout: fig.update_layout(xaxis=dict(range=[xlim[0],xlim[1]]))

Now if you try print(fig.layout.xaxis.range) you'll get the axis range.

This was bugging me a great deal so I had to dig deeper, credit goes to @Emmanuelle on the plotly forums for confirming this reality.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Plotly: How to plot a multiple y axis?

How to plot line curve with one x axis and two y axis with plotly?

how to plot two points on y axis for single x axis value (Maybe date) using plotly js

Plotly: How to set the range of the y axis?

How to set X axis range on plotly graphs?

How to change the x-axis and y-axis labels in plotly?

How to plot a vertical line at the x-axis range median position using plotly in Python API?

How to plot on R multiple variables on the X axis, and their values on the Y axis?

How to make a years on Y axis and months on X axis plot with pandas?

How to plot a graph with 2 variables on the x axis and count on the y axis?

Python Plotly Subplots: How to set dynamically different x and y axis for each plot

Plotly How to plot multiple lines with different X-arrays on the same Y-axis

Plotly: multiple x and y axis

How to change the range of the x-axis and y-axis in matlibplot?

Plotly: How to change the range of the y-axis of a subplot?

How to connect box plot medians with multicategory x axis in plotly python

Plotly: How to plot multiple lines with shared x-axis?

How to plot with same x and y axis range and interval between values using python?

X and Y axis plot date

Plotly: How to set y-axis ticklabels inside the plot / to the right of the axis?

How to plot in pandas - Different x and different y axis in a same plot

Plotly - change range of x-axis (date)

Set X Axis Range on Plotly Frequency Graph

How to get pandas to plot on the same graph with the same y axis range

How to adjust the y-axis range in effect_plot function

how to add reactive x and y axis labels to shiny plotly graph?

Plotly: How to make the x and y axis titles for subplots bigger?

How to vanish X and Y axis line from plotly graph

How to adjust the x-axis range in an effect plot