Skip to content

Commit

Permalink
GitBook: [master] 70 pages and 7 assets modified
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivy authored and gitbook-bot committed Jul 23, 2020
1 parent 8cbd3c7 commit 6f51594
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 0 deletions.
Binary file added .gitbook/assets/sales-perfromance.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
96 changes: 96 additions & 0 deletions plotly/6.2-basic-charts/6.2.2-advanced-bar-chart.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,98 @@
# 6.2.2 Advanced Bar Chart

### 1. Horizontal Bar

In [chapter 6.1.1](../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'`

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

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

![Grouped Horizontal Bar](../../.gitbook/assets/screenshot-2020-07-23-at-22.18.03.png)

```text
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 ](../../.gitbook/assets/screenshot-2020-07-23-at-22.19.10.png)

### 2. Relative Bar

```text
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](../../.gitbook/assets/screenshot-2020-07-24-at-00.01.54.png)

### 3. Customized Bar

```text
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](../../.gitbook/assets/sales-perfromance.gif)

```text
# 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](../../.gitbook/assets/screenshot-2020-07-23-at-23.55.45.png)

```text
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](../../.gitbook/assets/screenshot-2020-07-23-at-23.58.46.png)



0 comments on commit 6f51594

Please sign in to comment.