How do I show only the category tick, and rotate them, of a multicategory plotly bar chart
Asked Answered
I

1

7
  1. I wish to NOT show the inner category label in a multi-catogory bar chart using plotly graph-objects
  2. Further, I wish to rotate the label of the outer category label

This is my code

import pandas as pd
import plotly.graph_objects as go

df = pd.DataFrame({
  "City": ["Toronto", "Toronto", "Toronto", "CPH", "CPH", "London", "London"],
  "Tower name": ["T1", "T2", "T3", "T4", "T5", "T6","T7"],
  "Height": [1.0, 1.5, 2.0, 3.0, 4.0, 2.0 ,5.0],
})

fig = go.Figure(go.Bar(x=df.loc[:,["City", "Tower name"]].T.values, y=df["Height"].values))
fig.show()

The code gives the following output:

output

Desired output is as shown below:

desired output

To hide the inner category I have tried to create an empty column in my data as follows, but that doesn't work

df['empty'] = ""
fig = go.Figure(go.Bar(x=df.loc[:,["City", "Tower name"]].T.values, y=df["Height"].values))
fig.update_xaxes(ticktext = df['empty'])
fig.show()

to rotate the tickmarks I have used tickangle, but that only rotates the inner category. The city names remain unrotated

fig = go.Figure(go.Bar(x=df.loc[:,["City", "Tower name"]].T.values, y=df["Height"].values))
fig.update_xaxes(tickangle = -90)
fig.show()

output

This is a follow-up questions to the thread: Remove empty bars in grouped plotly express bar chart, such that the visual distance between each group of bars is equal

Instate answered 29/10, 2021 at 9:59 Comment(0)
M
0

Hiding sub-category axis labels in a multi-categorical axes is unfortunately not possible, as shown in this Github issue.

Rotating is not straightforward, but possible.

Mallen answered 7/9 at 20:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.