Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plotly: How to reverse axes?

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:

Graph

like image 274
astronerdF Avatar asked Nov 29 '19 06:11

astronerdF


People also ask

How do you change the y axis values in Plotly?

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.

How do you add axis labels in python?

To set labels on the x-axis and y-axis, use the plt. xlabel() and plt. ylabel() methods.


Video Answer


2 Answers

fig.update_yaxes(autorange="reversed", row=2, col=1)

Also works for subplots without changing the order for other plots

like image 73
A Rob4 Avatar answered Oct 07 '22 13:10

A Rob4


You can use:

fig['layout']['yaxis']['autorange'] = "reversed"

and:

fig['layout']['xaxis']['autorange'] = "reversed"

Plot - default axis:

enter image description here

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:

enter image description here

Plot - reversed y axis:

enter image description here

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()
like image 23
vestland Avatar answered Oct 07 '22 14:10

vestland