# 6.2.2 Advanced Bar Chart

### 1. Horizontal Bar

In [chapter 6.1.1](https://vecco-insight.gitbook.io/crash-visualization/6.1-fundamental-concepts/6.1.1-plotly-express#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](https://998709212-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MB-ky7fVqjeXA6EcAbW%2F-MCwA1EAVoUsk8URnz9P%2F-MCxKFqI9nulb3aJosIG%2FScreenshot%202020-07-23%20at%2022.18.03.png?alt=media\&token=e31748a4-d2e6-4b4d-a0db-e753103a567b)

```
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 ](https://998709212-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MB-ky7fVqjeXA6EcAbW%2F-MCwA1EAVoUsk8URnz9P%2F-MCxKaoOlHQRWkUGoxFe%2FScreenshot%202020-07-23%20at%2022.19.10.png?alt=media\&token=acad93fc-61b4-4d31-a1b6-1fe840da72dc)

### 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](https://998709212-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MB-ky7fVqjeXA6EcAbW%2F-MCxL4-Ye2TnWxf1Srff%2F-MCxgmGXsqfMkdmT6ZgC%2FScreenshot%202020-07-24%20at%2000.01.54.png?alt=media\&token=2259176b-f583-4a82-ad61-f09d45566eb4)

### 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](https://998709212-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MB-ky7fVqjeXA6EcAbW%2F-MCxi-qIK7EdwaIPVF4N%2F-MCxiZXZRgNbq_CMATrW%2Fsales%20perfromance.gif?alt=media\&token=bb9b891d-c88e-40bf-b9e1-cb483aaf5e3d)

```
# 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](https://998709212-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MB-ky7fVqjeXA6EcAbW%2F-MCxL4-Ye2TnWxf1Srff%2F-MCxgtG1N3OnZ3ykJvbg%2FScreenshot%202020-07-23%20at%2023.55.45.png?alt=media\&token=9d7052cc-0af6-417f-9f7e-71f8987b8753)

```
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](https://998709212-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MB-ky7fVqjeXA6EcAbW%2F-MCxL4-Ye2TnWxf1Srff%2F-MCxgvVd5G-ML2SMMuoS%2FScreenshot%202020-07-23%20at%2023.58.46.png?alt=media\&token=67bf27ca-dcf1-40d6-8944-2e2e8c9cceef)
