|
| 1 | +Seaborn helps you explore and understand your data. Its plotting functions operate on dataframes and arrays containing whole datasets and internally perform the necessary semantic mapping and statistical aggregation to produce informative plots. Its dataset-oriented, declarative API lets you focus on what the different elements of your plots mean, rather than on the details of how to draw them. |
| 2 | + |
| 3 | +Here’s an example of what seaborn can do: |
| 4 | +```Python |
| 5 | +# Import seaborn |
| 6 | +import seaborn as sns |
| 7 | + |
| 8 | +# Apply the default theme |
| 9 | +sns.set_theme() |
| 10 | + |
| 11 | +# Load an example dataset |
| 12 | +tips = sns.load_dataset("tips") |
| 13 | + |
| 14 | +# Create a visualization |
| 15 | +sns.relplot( |
| 16 | + data=tips, |
| 17 | + x="total_bill", y="tip", col="time", |
| 18 | + hue="smoker", style="smoker", size="size", |
| 19 | +) |
| 20 | +``` |
| 21 | +Below is the output for the above code snippet: |
| 22 | + |
| 23 | + |
| 24 | + |
| 25 | +```Python |
| 26 | +# Load an example dataset |
| 27 | +tips = sns.load_dataset("tips") |
| 28 | +``` |
| 29 | +Most code in the docs will use the `load_dataset()` function to get quick access to an example dataset. There’s nothing special about these datasets: they are just pandas data frames, and we could have loaded them with `pandas.read_csv()` or build them by hand. Many users specify data using pandas data frames, but Seaborn is very flexible about the data structures that it accepts. |
| 30 | + |
| 31 | +```Python |
| 32 | +# Create a visualization |
| 33 | +sns.relplot( |
| 34 | + data=tips, |
| 35 | + x="total_bill", y="tip", col="time", |
| 36 | + hue="smoker", style="smoker", size="size", |
| 37 | +) |
| 38 | +``` |
| 39 | +This plot shows the relationship between five variables in the tips dataset using a single call to the seaborn function `relplot()`. Notice how only the names of the variables and their roles in the plot are provided. Unlike when using matplotlib directly, it wasn’t necessary to specify attributes of the plot elements in terms of the color values or marker codes. Behind the scenes, seaborn handled the translation from values in the dataframe to arguments that Matplotlib understands. This declarative approach lets you stay focused on the questions that you want to answer, rather than on the details of how to control matplotlib. |
0 commit comments