# Order non-numeric y-axis

**URL:** <https://community.plotly.com/t/order-non-numeric-y-axis/53334>\
**Category:** 📊 Plotly Python\
**Created:** [May 26, 2021, 7:24pm UTC](https://community.plotly.com/t/order-non-numeric-y-axis/53334 "2021-05-26T19:24:52Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![PackElend](https://avatars.discourse-cdn.com/v4/letter/p/90ced4/32.png) [@PackElend](https://community.plotly.com/u/PackElend)\
**Post date:** [May 26, 2021, 7:24pm UTC](https://community.plotly.com/t/order-non-numeric-y-axis/53334/1 "2021-05-26T19:24:52Z")

</div>

Hi community,  
I have been playing around with [Histograms with Plotly Express: Complete Guide | by Vaclav Dekanovsky | Towards Data Science](https://towardsdatascience.com/histograms-with-plotly-express-complete-guide-d483656c5ad7) and [Categorical Axes | Python | Plotly](https://plotly.com/python/categorical-axes/) etc.  
I got my non-numerical values shown on the y-axis but not sorted the order I want.

My y-axis would by  
`yaxis_List = {"01", "02", "03", "04", "5A", "5B", "06", "07", "08", "09", "10", "30", "31", "40", "41", "50", "51"}`  
but it sorts it always alphanumeric or throws an error. I have tried pretty much all combination I can think of, going to the documentation of

```auto
    import plotly.graph_objects as go
    import plotly.express as px

```

So, I’m wondering if this is possible at all?  
All examples refer to a non-numeric x-axis.

thank you  
stefan

---

<div class="post-metadata">

**Author:** ![RenaudLN](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/renaudln/32/9041_2.png) [@RenaudLN](https://community.plotly.com/u/RenaudLN)\
**Post date:** [May 26, 2021, 11:44pm UTC](https://community.plotly.com/t/order-non-numeric-y-axis/53334/2 "2021-05-26T23:44:19Z")

</div>

Have you tried setting the category order? [Categorical Axes | Python | Plotly](https://plotly.com/python/categorical-axes/#controlling-the-category-order-with-plotly-express)

---

<div class="post-metadata">

**Author:** ![PackElend](https://avatars.discourse-cdn.com/v4/letter/p/90ced4/32.png) [@PackElend](https://community.plotly.com/u/PackElend)\
**Post date:** [May 27, 2021, 8:39am UTC](https://community.plotly.com/t/order-non-numeric-y-axis/53334/3 "2021-05-27T08:39:58Z")

</div>

looks like 🙂  
I tried the following

```auto
fig = go.Figure([go.Scatter(x=df['TIMESTAMP'], y=df['STEP'], category_orders = yaxis_List)])
...
fig.update_yaxes(type="category", categoryarray=tuple(yaxis_List), categoryorder='array')
fig.update_yaxes(type="category", category_orders=yaxis_List)

```

but without any success

---

<div class="post-metadata">

**Author:** ![RenaudLN](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/renaudln/32/9041_2.png) [@RenaudLN](https://community.plotly.com/u/RenaudLN)\
**Post date:** [May 27, 2021, 12:53pm UTC](https://community.plotly.com/t/order-non-numeric-y-axis/53334/4 "2021-05-27T12:53:29Z")

</div>

Works for me:

```python
categories_ordered = np.array(["01", "02", "03", "04", "5A", "5B", "06", "07", "08", "09", "10", "30", "31", "40", "41", "50", "51"])
categories_shuffled = categories_ordered.copy()
np.random.shuffle(categories_shuffled)
values = np.arange(categories_shuffled.shape[0])

fig = px.bar(
    pd.DataFrame(np.c_[categories_shuffled, values], columns=["x", "y"]),
    x="x",
    y="y",
    category_orders={"x": categories_ordered}
)
fig.show()

```

 ![image](https://us1.discourse-cdn.com/flex024/uploads/plot/original/2X/c/c5659a2208fab871ff1a28d7c981b0c1dccb2538.png)

---

<div class="post-metadata">

**Author:** ![PackElend](https://avatars.discourse-cdn.com/v4/letter/p/90ced4/32.png) [@PackElend](https://community.plotly.com/u/PackElend)\
**Post date:** [May 27, 2021, 1:12pm UTC](https://community.plotly.com/t/order-non-numeric-y-axis/53334/5 "2021-05-27T13:12:24Z")

</div>

> [@RenaudLN](#):
>
> ```auto
> category_orders={"x": categories_ordered}
> 
> ```

I’m sorry that I was not clear enough but the array shall be on the y-axis (vertical axis)

---

<div class="post-metadata">

**Author:** ![RenaudLN](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/renaudln/32/9041_2.png) [@RenaudLN](https://community.plotly.com/u/RenaudLN)\
**Post date:** [May 27, 2021, 1:27pm UTC](https://community.plotly.com/t/order-non-numeric-y-axis/53334/6 "2021-05-27T13:27:27Z")

</div>

Should work exactly the same on the vertical axis?

---

<div class="post-metadata">

**Author:** ![PackElend](https://avatars.discourse-cdn.com/v4/letter/p/90ced4/32.png) [@PackElend](https://community.plotly.com/u/PackElend)\
**Post date:** [May 27, 2021, 2:02pm UTC](https://community.plotly.com/t/order-non-numeric-y-axis/53334/7 "2021-05-27T14:02:48Z")

</div>

not exactly i

```auto
import numpy as np
import plotly.express as px
import pandas as pd

categories_ordered = np.array(["01", "02", "03", "04", "5A", "5B", "06", "07", "08", "09", "10", "30", "31", "40", "41", "50", "51"])
categories_shuffled = categories_ordered.copy()
np.random.shuffle(categories_shuffled)
values = np.arange(categories_shuffled.shape[0])

fig = px.bar(
    pd.DataFrame(np.c_[categories_shuffled, values], columns=["x", "y"]),
    x="x",
    y="y",
    category_orders={"y": categories_ordered}
)
fig.show()

```

does

 ![image](https://us1.discourse-cdn.com/flex024/uploads/plot/original/2X/4/4cb5b9778c0652a686198fb04d4ea1dda344cbf4.png)

y-axis values are not ordered as defined (ok, 0 to 16 is added but even below the order is not as defined)

---

<div class="post-metadata">

**Author:** ![RenaudLN](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/renaudln/32/9041_2.png) [@RenaudLN](https://community.plotly.com/u/RenaudLN)\
**Post date:** [May 27, 2021, 9:49pm UTC](https://community.plotly.com/t/order-non-numeric-y-axis/53334/8 "2021-05-27T21:49:06Z")

</div>

```python
px.bar(
    pd.DataFrame(np.c_[vals_shuffled, values], columns=["x", "y"]),
    x="y",
    y="x",
    category_orders={"x": vals_ordered},
    orientation="h"
)

```

 ![image](https://us1.discourse-cdn.com/flex024/uploads/plot/original/2X/d/d631a1fb77cfea40b6dfb3a8c418baeb6c7829a6.png)  
This?

---

<div class="post-metadata">

**Author:** ![PackElend](https://avatars.discourse-cdn.com/v4/letter/p/90ced4/32.png) [@PackElend](https://community.plotly.com/u/PackElend)\
**Post date:** [May 28, 2021, 2:43pm UTC](https://community.plotly.com/t/order-non-numeric-y-axis/53334/9 "2021-05-28T14:43:12Z")

</div>

rather this  
x-axis: time/date  
y-axis: category

 ![image](https://us1.discourse-cdn.com/flex024/uploads/plot/original/2X/e/e824a3c47abdc3cdd800b3b4ca508c44f74220f7.png)  
(painted in PowerPoint)

---

<div class="post-metadata">

**Author:** ![PackElend](https://avatars.discourse-cdn.com/v4/letter/p/90ced4/32.png) [@PackElend](https://community.plotly.com/u/PackElend)\
**Post date:** [June 1, 2021, 11:27am UTC](https://community.plotly.com/t/order-non-numeric-y-axis/53334/10 "2021-06-01T11:27:31Z")

</div>

any chance to get my painted chart done with plotly?
