Making a scatterplot in plotnine¶
Scatter plots are simple in plotnine! After setting your x and y axes, you use geom_point()
to draw a point for each of your datapoints.
In [1]:
Copied!
import pandas as pd
from plotnine import *
df = pd.read_csv('countries.csv')
df.head(2)
import pandas as pd
from plotnine import *
df = pd.read_csv('countries.csv')
df.head(2)
Out[1]:
country | continent | gdp_per_capita | life_expectancy | population | |
---|---|---|---|---|---|
0 | Afghanistan | Asia | 663 | 54.863 | 22856302 |
1 | Albania | Europe | 4195 | 74.200 | 3071856 |
In [2]:
Copied!
(
ggplot(df)
+ aes(x='gdp_per_capita', y='life_expectancy')
+ geom_point()
)
(
ggplot(df)
+ aes(x='gdp_per_capita', y='life_expectancy')
+ geom_point()
)
Out[2]:
<ggplot: (319471598)>
In [ ]:
Copied!