Hello, Iām new to plotly and was having some trouble formatting my y axis. I want to use a specific order for my y axis values (name1, name2, name3), and be able to display all of them in the axis even if there are no values for a corresponding y axis tick. Some sample code:
import pandas as pd
import plotly.graph_objects as go
data = [['name1','name2','name3','name3','name2','name1'],['name2','name2','name3','name3','name2','name3'],
['name1','name1','name2','name2','name2','name2']]
df = pd.DataFrame(data, columns = ['1','2','3','4','5','6'])
x = df.iloc[0, 1:].tolist()
y = df.iloc[1, 1:].tolist()
z = df.iloc[2, 1:].tolist()
fig = go.Figure()
xaxis = [1,2,3,4,5,6]
fig.add_trace(
go.Scatter(x=xaxis, y=x, mode='markers', showlegend=False))
fig.update_xaxes(title_text="Columns", ticks="outside", showgrid=False, zeroline=False, showline=True, linecolor='black')
fig.update_yaxes(title_text="Names", ticks="outside", showgrid=True, zeroline=False, showline=True, linecolor='black')
fig.show()
Which produces (when the first row is plotted) :
and (when the second row is plotted) :
I want to be able to set the order of the y axis to be name1, name2, name3 (graph 1 is unsorted) and make all them appear on all graphs regardless if there are values or not (the second graph does not display name1 as a tick).
Thank you!