Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the functions of Seaborn

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "what are the functions of Seaborn". The content of the explanation in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn what functions Seaborn has.

Basic information

Seaborn is a library that uses Python to make statistical graphics. It is built on matplotlib and is tightly integrated with panda data structures.

Here are some of the features provided by seaborn:

A dataset-oriented API for checking the relationship between multiple variables

Specifically supports the use of classified variables to display observations or aggregate statistics

Options for visualizing univariate or bivariate distributions and comparing subsets of data

Automatic estimation and Mapping of various dependent variable Linear regression models

It is easy to view the overall structure of complex data sets.

High-level abstraction for building multi-block grids, allowing you to easily build complex visualization

Concise control of matplotlib graphic styles and several built-in themes

Select a palette tool to faithfully reveal your data pattern

The goal of Seaborn is to make visualization a central part of exploring and understanding data. Its dataset-oriented drawing function operates on data streams and arrays that contain the entire dataset, and internally performs the necessary semantic mapping and statistical aggregation to generate information graphs.

Here is an example:

Import seaborn as snssns.set () tips = sns.load_dataset ("tips") sns.relplot (x = "total_bill", y = "tip", col= "time", hue= "smoker", style= "smoker", size= "size", data=tips)

Something happened here. Let's look at it one by one:

1. We import seaborn, which is the only library required for this simple example.

Import seaborn as sns

Behind the scenes, seaborn uses matplotlib to draw pictures. Many tasks can only be done through the seaborn function, but further customization may require the direct use of matplotlib. This will be explained in more detail below. For interactive work, it is recommended to use the Jupyter/IPython interface in matplotlib mode, otherwise you must call matplotlib.pyplot.show to view the picture.

two。 We apply the default default seaborn themes, zooms, and palettes.

Sns.set ()

This will use the matplotlib rcParam system and will affect the appearance of all matplotlib diagrams, even if you are not using seaborn to create them. In addition to the default theme, there are several other options where you can independently control the style and scale of the drawing to quickly transform your work in the presentation context (for example, generate a drawing with a readable font during a presentation). If you like the default settings of matplotlib, or if you like different themes, you can skip this step and still use the seaborn drawing function.

3. Let's load a sample dataset

Tips = sns.load_dataset ("tips")

Most of the code in the document will use the load_dataset () function to quickly access the sample dataset. There's nothing special about these datasets; they're just pandas's data warehouses, and we can load pandas into them, read_csv them or build them by hand. Many of the examples use the "tips" dataset, which is very boring but useful for demos. Tips datasets illustrate a "neat" way to organize datasets. If your dataset is organized in this way, you will get the most benefit from seaborn, which will be explained in more detail below

4. We draw a faceted scatter graph with multiple semantic variables.

Sns.relplot (x = "total_bill", y = "tip", col= "time", hue= "smoker", style= "smoker", size= "size", data=tips)

This special diagram shows the relationship between the five variables in the tips dataset. Three of them are numerical and two are classified. Two numeric variables (total_bill and tip) determine the location of each point on the axis, and the third variable (size) determines the size of each point. One classification variable divides the dataset into two different axes (facet), and the other determines the color and shape of each point.

All of this is done through a single call to the seaborn function relplot (). Note that we only provide the names of the variables in the dataset and the role we want them to play in the diagram. Unlike using matplotlib directly, you do not need to convert variables to visual parameters (for example, specific colors or markers used for each category). The translation is done automatically by seaborn. This allows users to focus on the questions they want the picture to answer.

Replot function and kind parameter

There is no universal best method of data visualization. Different questions are best answered through different visualization. Seaborn attempts to simplify switching between different visual representations that can be parameterized using the same dataset-oriented API.

The relplot () function is named because it is designed to visualize many different statistical relationships. Although scatter plots are a very effective method, a variable representing the relationship of time measurements is best represented by a line. The relplot () function has a convenient argument, kind, which can be easily switched to this alternative representation:

Dots = sns.load_dataset ("dots") sns.relplot (x = "time", y = "firing_rate", col= "align", hue= "choice", size= "coherence", style= "choice", facet_kws=dict (sharex=False), kind= "line", legend= "full", data=dots))

Notice how the size and style parameters are shared in scatter and line graphs, but their effects on the two visualization are different (changing marker areas and symbols and lineweights and dashed lines). We don't need to remember these details, let's focus on the overall structure of the plot and the message we want to convey.

Statistical estimates and error bars

Usually what we are interested in is the average of a variable as a function of other variables. Many shipping functions can perform statistical estimates automatically, which is necessary to answer these questions:

Fmri = sns.load_dataset ("fmri") sns.relplot (x = "timepoint", y = "signal", col= "region", hue= "event", style= "event", kind= "line", data=fmri)

When the statistics are estimated, seaborn uses bootstrapping to calculate the confidence interval and draw error bars that represent the uncertainty of the estimate.

Seaborn's statistical estimates go beyond descriptive statistics. For example, you can also use lmplot () to enhance a scatter chart to include a linear regression model (and its uncertainty):

Sns.lmplot (x = "total_bill", y = "tip", col= "time", hue= "smoker", data=tips

Professional classification chart

Standard scatter and line graphs show the relationship between numerical variables, but many data analyses involve classified variables. There are several specialized drawing types in seaborn that are optimized to visualize this type of data. You can access them through catplot (). Similar to relplot (), the idea of catplot () is to expose a generic dataset-oriented API that generalizes on different representations of the relationship between a numeric variable and one (or more) classified variables.

These representations provide different levels of granularity when representing the underlying data. At the finest level, you may want to adjust the position of points on the classification axis by drawing scatter graphs so that they do not overlap:

Sns.catplot (x = "day", y = "total_bill", hue= "smoker", kind= "swarm", data=tips)

Alternatively, you can use kernel density estimates to represent the underlying distribution of sampling points:

Sns.catplot (x = "day", y = "total_bill", hue= "smoker", kind= "violin", split=True, data=tips)

Or you can display a unique average and its confidence interval in each nested category:

Sns.catplot (x = "day", y = "total_bill", hue= "smoker", kind= "bar", data=tips)

Visual dataset structure

There are two other graph-level functions in seaborn that can be used to visualize multiple blocks. They are all oriented to the dataset structure. One is jointplot (), which focuses on a single relationship:

Iris = sns.load_dataset ("iris") sns.jointplot (x = "sepal_length", y = "petal_length", data=iris)

The other is pairplot (), which has a broader view, showing all pairwise relationships and marginal distributions, optionally subject to a classification variable:

Sns.pairplot (data=iris, hue= "species")

In terms of visual representation, jointplot () and pairplot () both have different options, both of which are based on classes that allow more thorough customization of multiple plot graphics (JointGrid and PairGrid, respectively).

Thank you for your reading, the above is the content of "what functions does Seaborn have?" after the study of this article, I believe you have a deeper understanding of what functions Seaborn has, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report