Manually Setting y-axis height for plot widget

Good morning Gang!

I am trying to see what the most performant way to set the height of a plot widget using the function:

from plotly import graphic_objs as go

go.Scatter() 

The documentation for this Scatter plot says to use this function as an object constructor and then apply the go.Layout function to change the values as such:

trace1 = go.Scatter(
    x=[0, 1, 2, 3, 4, 5, 6, 7, 8],
    y=[8, 7, 6, 5, 4, 3, 2, 1, 0]
)
trace2 = go.Scatter(
    x=[0, 1, 2, 3, 4, 5, 6, 7, 8],
    y=[0, 1, 2, 3, 4, 5, 6, 7, 8]
)
data = [trace1, trace2]
layout = go.Layout(
    xaxis=dict(
        range=[2, 5]
    ),
    yaxis=dict(
        range=[2, 5]
    )
)
fig = go.Figure(data=data, layout=layout)

I didn’t want to configure the height of the object if the anvil workstation is already setting up the height of the widget. ( I have it set to the default 196; but it is not coming out to the height that I have it in the editor. ) Maybe the height that I set in the drag and drop workstation is only the maximum height for the widget?

Do you have an example to clone? If it is in a container that might cap the dimensions.

1 Like

Just figured it out, the default 196 number plot widgets come with is very small and when I boosted it to 300 it went up nicely. I was trying to fix it programatically using anvil’s capabilties are best.

Yeah - if you want to edit the Layout object, you’ll want to edit the Plot’s layout property. Like this:

self.plot_1.layout.xaxis.range = [2,5]
1 Like