# 6.2.2 Advanced Bar Chart

### 1. Horizontal Bar

In [chapter 6.1.1](/crash-visualization/plotly/6.1-fundamental-concepts/6.1.1-plotly-express.md#2-bar-chart) we have shown several regular bar charts. To make a horizontal bar is very intuitive, you just need to add a `'orientation='h'`

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

```
df = px.data.tips()
fig = px.bar(df, x="total_bill", y="day", orientation='h')
fig.show()
```

![Grouped Horizontal Bar](/files/-MCxKFqI9nulb3aJosIG)

```
fig = px.bar(df, x="total_bill", y="time", color='day', orientation='h',
             hover_data=["tip", "size"], height=400, title='Restaurant bills')
fig.show()
```

![Stacked Horizontal Bar ](/files/-MCxKaoOlHQRWkUGoxFe)

### 2. Relative Bar

```
x = ['a', 'b', 'c', 'd']

fig = go.Figure()
fig.add_trace(go.Bar(x=x, y=[1, 4, 9, 16],name = 'sales Revenue'))
fig.add_trace(go.Bar(x=x, y=[6, -8, -4.5, 8]))
fig.add_trace(go.Bar(x=x, y=[-15, -3, 4.5, -8]))
fig.add_trace(go.Bar(x=x, y=[-1, 3, -3, -4]))

fig.update_layout(barmode='relative', title_text='Relative Bar: Cashflow example')
fig.show()
```

![Relative Bar](/files/-MCxgmGXsqfMkdmT6ZgC)

### 3. Customized Bar

```
fruit = ['apple','orange','banana']
fig = go.Figure()

fig.add_trace(go.Bar(
    y=fruit ,x=[14, 18, 26],
    name='Q1 Sales', orientation='h',
    marker=dict(
        color='greenyellow', line=dict(color='#f3f3f3', width=3)
    )
))
fig.add_trace(go.Bar(
    y=fruit, x=[30, 50, 40],
    name='Q2 Sales', orientation='h',
    marker=dict(
        color='dodgerblue', line=dict(color='#f3f3f3', width=3)
    )
))
fig.update_layout(barmode='stack')
fig.show()
```

![Customerized Bar](/files/-MCxiZXZRgNbq_CMATrW)

```
# bar with annotations
df = px.data.gapminder().query("continent == 'Europe' and year == 2007 and pop > 10.e6")
fig = px.bar(df, y='pop', x='country', text='pop')
fig.update_traces(texttemplate='%{text:.2s}', textposition='outside')
fig.update_layout(uniformtext_minsize=8, uniformtext_mode='hide')
fig.show()
```

![Bar with text annotations](/files/-MCxgtG1N3OnZ3ykJvbg)

```
colors = ['dodgerblue',] * 5
colors[3] = 'firebrick'

fig = go.Figure(data=[go.Bar(
    x=['Jonas', 'Julian', 'Marius',
       'Adrien', 'Jane'],
    y=[80, 85, 79, 50, 90],
    marker_color=colors # marker color can be a single color value or an iterable
)])
fig.update_layout(title_text= 'Students Score')
```

![Bar with Customized colors](/files/-MCxgvVd5G-ML2SMMuoS)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://vecco-insight.gitbook.io/crash-visualization/plotly/6.2-basic-charts/6.2.2-advanced-bar-chart.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
