...
/Handling Overplotting and Outlier Values
Handling Overplotting and Outlier Values
Learn how to tackle overplotting and outlier values in datasets.
We'll cover the following...
Let’s say we are now interested in seeing the relationship between our variable and population for the same year that we have been working on. We want to have Population, total
on the axis and perc_pov_19
on the axis.
We first create a subset of poverty
in which year
is equal to 2010 and is_country
is True
, and sort the values using Population, total
:
df =\
poverty[poverty['year'].eq(2010) & poverty['is_country']]
.sort_values('Population, total')
Now let’s see how to plot those two variables. Here is the code:
px.scatter(df,
y=perc_pov_19,
x='Population, total',
title=' - '.join([perc_pov_19, '2010']),
height=500)
Running this produces the chart in the Jupyter Notebook set up below:
Please login to launch live app!
- The existence of one outlier, China, with a population close to 1.4 billion, forces all markers to be squeezed into a very narrow part of our chart.
- We also have a small cluster of values above 25 on the axis, but the difference is nowhere as extreme as the horizontal one.
- Another important issue is that there are many markers on top of one another. Having solid-colored markers means that if we plot one marker on top of another, it won’t make any difference—not even a thousand