👀
Crash Visualization
  • Welcome
  • Preface
    • Who the book is written for
    • How the book is organized
  • 1. Introduction of Data Visualization
    • 1.1 What is data visualization?
    • 1.2 Why does visualization matter?
  • 2. Tricks in Visualization
    • 2.1 Choose Appropriate Chart
    • 2.2 Features of Charts
      • 2.2.1 Table
      • 2.2.2 Column Chart
      • 2.2.3 Line Chart
      • 2.2.4 Pie Chart
      • 2.2.5 Scatter Chart
      • 2.2.6 Map Chart
    • 2.3 Misused Graph
    • 2.4 Tips in Visualization
  • 3. Matplotlib
    • 3.1 Basic Concepts
    • 3.2 Line Chart
    • 3.3 Area Chart
    • 3.4 Column Chart
    • 3.5 Histogram Chart
    • 3.6 Scatter Chart
    • 3.7 Lollipop Chart
    • 3.8 Pie Chart
    • 3.9 Venn Chart
    • 3.10 Waffle Chart
    • 3.11 Animation
  • 4. Seaborn
    • 4.1 Trends
    • 4.2 Ranking
      • 4.2.1 Barplot
      • 4.2.2 Boxplot
    • 4.3 Composition
      • 4.3.1 Stacked Chart
    • 4.4 Correlation
      • 4.4.1 Scatter Plot
      • 4.4.2 Linear Relationship
      • 4.4.3 Heatmap
      • 4.4.4 Pairplot
    • 4.5 Distribution
      • 4.5.1 Boxplot
      • 4.5.2 Violin plot
      • 4.5.3 Histogram plot
      • 4.5.4 Density plot
      • 4.5.5 Joint plot
  • 5. Bokeh
    • 5.1 Basic Plotting
    • 5.2 Data Sources
    • 5.3 Annotations
    • 5.4 Categorical Data
    • 5.5 Presentation and Layouts
    • 5.6 Linking and Interactions
    • 5.7 Network Graph
    • 5.8 Widgets
  • 6. Plotly
    • 6.1 Fundamental Concepts
      • 6.1.1 Plotly Express
      • 6.1.2 Plotly Graph Objects
    • 6.2 Advanced Charts
      • 6.2.1 Advanced Scatter Chart
      • 6.2.2 Advanced Bar Chart
      • 6.2.3 Advanced Pie Chart
      • 6.2.4 Advanced Heatmap
      • 6.2.5 Sankey Chart
      • 6.2.6 Tables
    • 6.3 Statistical Charts
      • 6.3.1 Common Statistical Charts
      • 6.3.2 Dendrograms
      • 6.3.3 Radar Chart
      • 6.3.4 Polar Chart
      • 6.3.5 Streamline Chart
    • 6.4 Financial Charts
      • 6.4.1 Funnel Chart
      • 6.4.2 Candlestick Chart
      • 6.4.3 Waterfall Chart
  • Support
    • Donation
Powered by GitBook
On this page
  • 1. Horizontal Bar
  • 2. Relative Bar
  • 3. Customized Bar

Was this helpful?

  1. 6. Plotly
  2. 6.2 Advanced Charts

6.2.2 Advanced Bar Chart

Previous6.2.1 Advanced Scatter ChartNext6.2.3 Advanced Pie Chart

Last updated 4 years ago

Was this helpful?

1. Horizontal Bar

In 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()
fig = px.bar(df, x="total_bill", y="time", color='day', orientation='h',
             hover_data=["tip", "size"], height=400, title='Restaurant bills')
fig.show()

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()

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()
# 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()
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')

chapter 6.1.1
Grouped Horizontal Bar
Stacked Horizontal Bar
Relative Bar
Customerized Bar
Bar with text annotations
Bar with Customized colors