How can I get the resulting x-axis and y-axis limits in a plot?


Steven Camden

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

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 x-axis min and max seem to be around ~10 and ~29, but I need a way to generate precise values ​​for the axis range.

enter image description here

Is there a way to access the generated axis limits?

Yogyakarta

There is no way to get the axis limits from the plot in the python implementation. The axis range can only be retrieved if it is specified in the layout (but it is not actually needed).

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

If you need constraints, you need to make your own constraints and apply them to the layout:

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

Now, if you try it, you print(fig.layout.xaxis.range)will get the axis limits.

This annoyed me so much that I had to dig deeper , thanks to @Emmanuelle on the conspiracy forum for confirming this reality.

Related


How can I change the x-axis limits in the contour plot?

Kunal Singhal I want my plot to also show 7000 on the x-axis, since there are more than 6000 values in the data. I try to use, set_xlim(right = 7000)but an error pops up 'QuadContourSet' object has no attribute 'set_xlim' import numpy as np import matplotlib.p

How can I change the x-axis limits in the contour plot?

Kunal Singhal I want my plot to also show 7000 on the x-axis, since there are more than 6000 values in the data. I try to use, set_xlim(right = 7000)but an error pops up 'QuadContourSet' object has no attribute 'set_xlim' import numpy as np import matplotlib.p

How can I add an X axis to the plot?

Ann Kribel I'm trying to plot some data, but I don't know how to add date values on the x-axis of the chart. Here is my code: import pandas as pd import numpy as np %matplotlib inline %pylab inline import matplotlib.pyplot as plt pylab.rcParams['figure.figsiz

How can I add an X axis to the plot?

Ann Kribel I'm trying to plot some data, but I don't know how to add date values on the x-axis of the chart. Here is my code: import pandas as pd import numpy as np %matplotlib inline %pylab inline import matplotlib.pyplot as plt pylab.rcParams['figure.figsiz

How can I exaggerate the Y axis of an SVG plot?

Gilkov Arpa In this SVG chart, the lines are too flat. How can I exaggerate the difference in the Y value of the points to make it look more "zigzag", with the lowest point of the line at the bottom of the chart and the highest point at the top? svg { displa

How can I set the X-axis range on the plot?

lucky I am using the R version of plotly. This is what I want: x = 1:100 y = 1:100 plot_ly(x, y) I want the plot to only show where x > 20 and x < 40 and ignore other parts. How to do this? hpesoj626 set . layout_xaxis y = 1:100 plot_ly(x=~x, y=~y) %>% layo

How can I set the X-axis range on the plot?

lucky I am using the R version of plotly. This is what I want: x = 1:100 y = 1:100 plot_ly(x, y) I want the plot to only show where x > 20 and x < 40 and ignore other parts. How to do this? hpesoj626 set . layout_xaxis y = 1:100 plot_ly(x=~x, y=~y) %>% layo

How can I plot time on the x-axis?

Mahmoud Abdul-Rahman I want to create a bar chart where the x-axis are the columns in datetimemy dataframe. I converted the datetimein pandascolumn to time only and when I try to use the matplotlib.pyplot.barplotfunction to plot the data I get an error : impor