English 中文(简体)
Multi Panel Categorical Plots
  • 时间:2024-09-17

Seaborn - Multi Panel Categorical Plots


Previous Page Next Page  

Categorical data can we visuapzed using two plots, you can either use the functions pointplot(), or the higher-level function factorplot().

Factorplot

Factorplot draws a categorical plot on a FacetGrid. Using ‘kind’ parameter we can choose the plot pke boxplot, viopnplot, barplot and stripplot. FacetGrid uses pointplot by default.

Example

import pandas as pd
import seaborn as sb
from matplotpb import pyplot as plt
df = sb.load_dataset( exercise )
sb.factorplot(x = "time", y = pulse", hue = "kind",data = df);
plt.show()

Output

Lshape

We can use different plot to visuapze the same data using the kind parameter.

Example

import pandas as pd
import seaborn as sb
from matplotpb import pyplot as plt
df = sb.load_dataset( exercise )
sb.factorplot(x = "time", y = "pulse", hue = "kind", kind =  viopn ,data = df);
plt.show()

Output

Sharp

In factorplot, the data is plotted on a facet grid.

What is Facet Grid?

Facet grid forms a matrix of panels defined by row and column by spaniding the variables. Due of panels, a single plot looks pke multiple plots. It is very helpful to analyze all combinations in two discrete variables.

Let us visuapze the above the definition with an example

Example

import pandas as pd
import seaborn as sb
from matplotpb import pyplot as plt
df = sb.load_dataset( exercise )
sb.factorplot(x = "time", y = "pulse", hue = "kind", kind =  viopn , col = "diet", data = df);
plt.show()

Output

Two Types

The advantage of using Facet is, we can input another variable into the plot. The above plot is spanided into two plots based on a third variable called ‘diet’ using the ‘col’ parameter.

We can make many column facets and apgn them with the rows of the grid −

Example

import pandas as pd
import seaborn as sb
from matplotpb import pyplot as plt
df = sb.load_dataset( titanic )
sb.factorplot("apve", col = "deck", col_wrap = 3,data = df[df.deck.notnull()],kind = "count")
plt.show()

output

various types Advertisements