4.1 Trends
1. Quick start
You can set aesthetic parameters in one step by sns.set()
font_scale: Separate scaling factor to independently scale the size of the font elements.
style: dict, None, or one of {darkgrid, whitegrid, dark, white, ticks}
palette: Color palette, see
color_palette()
​
You can set aesthetic parameters in one step by sns.set()
font_scale: Separate scaling factor to independently scale the size of the font elements.
style: dict, None, or one of {darkgrid, whitegrid, dark, white, ticks}
palette: Color palette, see
color_palette()
​
2. Simple plot
Firstly, let us create a simple dataset. The head of the dataset looks as below:
Then, we can plot a very simple line chart. Since we've already set all the aesthetic parameters at the beginning, here the code is pretty short and clean.
We can not only plot a full dataset, but also pieces of the dataset. For example, I will truncate two lists of data from the original dataset. One is in a different period, the other is in the same period. Then we put them together by plt.subplots()
‌
a and b are different lines in different periods.
c and c are different lines in the same period.
3. Smart plot
More complex datasets will have multiple measurements for the same value of the x variable. The default behavior in seaborn is to aggregate the multiple measurements at each x value by plotting the mean and the 95% confidence interval ( grey area) around the mean. Let us take the "fmri" dataset for example.
The relationship between x
and y
can be shown for different subsets of the data using the hue
, size
, and style
parameters. These parameters control what visual semantics are used to identify the different subsets.
hue: Grouping variable that will produce lines with different colors. Can be either categorical or numeric, although color mapping will behave differently in the latter case.
size: Grouping variable that will produce lines with different widths. Can be either categorical or numeric, although size mapping will behave differently in the latter case.
style: Grouping variable that will produce lines with different dashes and/or markers. Can have a numeric type but will always be treated as categorical.
‌
For example, seaborn groups variables in the "fmri" dataset and show the groups with different colors, and use color and line dashing to represent two different grouping variables.
4. Facet plot
The chart above is quite complicated and not user-friendly. People need to read slowly and carefully to get the information. In this case, we need to consider another way to deliver the same information but more clear.‌
​FacetGrid
is a useful approach is to draw multiple instances of the same plot on different subsets of the dataset. It allows a viewer to quickly extract a large amount of information about complex data.‌
We can Use relplot()
to combine lineplot()
and FacetGrid
​
Last updated