Categorical scatter plot

With the data classified into categories, we can check whether different population types exhibit different Big Mac index distributions.

We can use seaborn.lmplot to dissect the data and create a categorical scatter plot. As a recap, lmplot() combines regplot() with FacetGrid for visualization of three or more pairs of variables in faceted grids or color-coded scatter plots. In the upcoming examples, we are going to assign the population type variable to the col, row, or hue parameters of lmplot(). Let's see how the results look:

# Horizontal faceted grids (col="population type")
g = sns.lmplot(x="Value", y="dollar_price", col="population type", data=merged_df2)
g.set_xlabels("GDP per capita (constant 2000 US$)")
g.set_ylabels("BigMac index (US$)")

plt.show()

The preceding code excerpt generates:

Alternatively, if we set row="population type" instead of col="population type" in the code excerpt, the following plot will be generated:

Finally, by changing col="population type" to hue="population type" , a color-coded categorical scatter plot will be generated:

In fact, col, row, and hue can be mixed together to create a rich faceted grid. This is particularly useful when there are lots of dimensions in your data. Further discussion of facet grids will be available in the next chapter.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset