Seaborn is a popular Python visualization library built on top of matplotlib
that provides a high-level interface for drawing attractive and informative statistical graphics. These plots require titles and labels (on the x and y axes) to present data vividly. Moreover, since Seaborn is built on top of the matplotlib.pyplot
library, it can easily be linked with commonly used libraries (e.g., pandas).
In seaborn
, we use the x
and y
parameters of the sns.boxplot()
function to label the x and y-axis and the .set()
to add a title to the plot.
Let’s create a box plot and label it as follows:
import pandas as pdimport seaborn as snsimport matplotlib.pyplot as pltdf = pd.DataFrame({'Score': [33, 24, 29, 25, 30, 29, 34, 37],'Player': ['X', 'X', 'X', 'X', 'Y', 'Y', 'Y', 'Y']})sns.boxplot(data=df, x='Player', y='Score').set(title='Points by Player')
df
.sns.boxplot()
function to create a boxplot and set the labels and the .set()
attribute to add a title.Here, seaborn
stores the boxplot as a list and then uses its show()
function to print it.
Free Resources