LoslegenKostenlos loslegen

Bar graph of sales by country

The global e-commerce company greatly enjoyed your work on their line figure. However, they have a more challenging task for you and want to see if your Plotly powers are customizable enough for their corporate reporting requirements.

They would like to be able to visualize total sales by Country but want to ensure the bars are clear and separate enough to see each distinctly. This is a tricky one, but you are up to the challenge!

Diese Übung ist Teil des Kurses

Building Dashboards with Dash and Plotly

Kurs anzeigen

Anleitung zur Übung

  • Create a bar graph object called bar_fig.
  • Set the graph to be horizontal.
  • Update the layout of bar_fig to increase the distance between bars.

Interaktive Übung

Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.

import pandas as pd
import plotly.express as px
ecom_sales = pd.read_csv('/usr/local/share/datasets/ecom_sales.csv')
ecom_sales = ecom_sales.groupby('Country')['OrderValue'].agg('sum').reset_index(name='Total Sales ($)')

# Create the bar graph object
bar_fig = px.____(
  data_frame=ecom_sales, x='Total Sales ($)', y='Country',
  # Set the graph to be horizontal
  ____='h', title='Total Sales by Country')

# Increase the gap between bars
bar_fig.____({'bargap': 0.5})

bar_fig.show()
Code bearbeiten und ausführen