...
/Creating a Plotly Express Chart Using the Dataset
Creating a Plotly Express Chart Using the Dataset
Learn how to create express charts using Plotly.
We'll cover the following...
Summarizing a dataset using scatterplots
Let’s see how we might summarize the poverty data_frame
with a scatterplot.
Press + to interact
# create variablesyear = 2010indicator = 'Income share held by lowest 10%'grouper = 'Region'# create DataFramedf = (poverty[poverty['year'].eq(year)].sort_values(indicator).dropna(subset=[indicator, grouper]))#settign parametersfig= 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 (usingcolor
andsymbol
) 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 toyear
, sorted the values byindicator
, and removed any missing values from the columns ofindicator
andgrouper
...