I want to reverse the y-axis of the graph I've obtained for all the over-plots using plotly.graph_objects. I know reversing of the axis can be done using plotly.express. But I would like to know how to reverse the axis using plotly.graph_objects
:
You can pass a dict in the keyword argument yaxis . It could be something like go. Layout(yaxis=dict(range=[0, 10])) I hope this helps you.
To set labels on the x-axis and y-axis, use the plt. xlabel() and plt. ylabel() methods.
fig.update_yaxes(autorange="reversed", row=2, col=1)
Also works for subplots without changing the order for other plots
You can use:
fig['layout']['yaxis']['autorange'] = "reversed"
and:
fig['layout']['xaxis']['autorange'] = "reversed"
Plot - default axis:
Code:
import plotly.graph_objects as go
import numpy as np
t = np.linspace(0, 5, 200)
y = np.sin(t)
fig = go.Figure(data=go.Scatter(x=t, y=y, mode='markers'))
fig.show()
Plot - reversed x axis:
Plot - reversed y axis:
Code - reversed axes:
import plotly.graph_objects as go
import numpy as np
t = np.linspace(0, 5, 200)
y = np.sin(t)
fig = go.Figure(data=go.Scatter(x=t, y=y, mode='markers'))
fig['layout']['xaxis']['autorange'] = "reversed"
fig['layout']['yaxis']['autorange'] = "reversed"
fig.show()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With