Facet row and Facet columns are not organized as ascending/descending sequence of values

I have a dataset stored in a pandas dataframe. I plot them using plotly.express. My code is given below.

As you can see the facet columns are not organized as per ascending/descending value of the “Vov” field. The same is true for facet row. I look for the unique values of “Vov” and “T” field from the dataframe. It turns out that plotly is just following the sequence that comes from the data[‘Vov’].unique() command.

I also checked, the datatype of both the “Vov” field and “T” field is float64, not str.

How can I organize the facet rows and columns in a right sequence?

fig = px.scatter(data, x=“x”, y=“y”, color=round(np.log10(data[“z”])), facet_col=data[“Vov”],facet_row=‘T’)
fig.update_layout(coloraxis_colorbar=dict(title=“Z”,))
fig.update_yaxes(type=“log”)
fig.update_xaxes(type=“log”)
fig.show()


image

PX sorts by data frame order by default but this is overrideable, so you can either pre-sort your dataframe, or you can manually force the sequence using the category_orders parameter. There are some examples here: https://plotly.com/python/styling-plotly-express/

Thanks you :slight_smile:
It works as I wanted.