set the y-axis limits of a plotly figure in python

To set the y-axis limits of a Plotly figure in Python, you can use the update_yaxes method from the plotly.graph_objects module. Here is an example:

main.py
import plotly.graph_objects as go

# Create a sample figure
fig = go.Figure(data=go.Scatter(x=[1, 2, 3, 4, 5], y=[1, 3, 2, 4, 1]))

# Set the y-axis limits
fig.update_yaxes(range=[0, 5])

# Display the figure
fig.show()
220 chars
11 lines

In this example, update_yaxes(range=[0, 5]) sets the y-axis limits from 0 to 5. You can adjust the values [0, 5] to fit your specific needs.

By calling the show() method on the figure, you can display the updated plot with the set y-axis limits.

related categories

gistlibby LogSnag