...

/

Creating a Plotly Express Chart Using the Dataset

Creating a Plotly Express Chart Using the Dataset

Learn how to create express charts using Plotly.

Summarizing a dataset using scatterplots

Let’s see how we might summarize the poverty data_frame with a scatterplot.

Press + to interact
# create variables
year = 2010
indicator = 'Income share held by lowest 10%'
grouper = 'Region'
# create DataFrame
df = (poverty[poverty['year'].eq(year)]
.sort_values(indicator)
.dropna(subset=[indicator, grouper]))
#settign parameters
fig= px.scatter(data_frame=df,
x=indicator,
y='Country Name',
color=grouper,
symbol=grouper,
log_x=True,
hover_name=df['Short Name'] + ' ' + df['flag'],
size=[1]* len(df),
title= ' '.join([indicator, 'by', grouper, str(year)]),
height=700)
  • Lines 2–4: We create variables for year, indicator, and a grouping (grouper) metric to use in the visualization. The grouping metric will be used to distinguish between the markers (using color and symbol) and could take any categorical value from the dataset, such as region, income group, and so on.

  • Lines 7–9: Based on these variables, we created a DataFrame in which the year column is equal to year, sorted the values by indicator, and removed any missing values from the columns of indicator and grouper ...