# 4.4.1 Scatter Plot

A scatter plot uses dots to represent values for two different numeric variables. The position of each dot on the horizontal and vertical axis indicates values for an individual data point. Scatter plots are used to observe relationships between variables.

The primary uses of the scatter plot are to observe and show relationships between two numeric variables. The dots in a scatter plot not only report the values of individual data points but also patterns when the data are taken as a whole.

```
import seaborn as sns    #  import the library
plt.style.use('seaborn-pastel')  #  set the style  and color palette

# set the font size and figure size at once
plt.rcParams.update({'font.size': 18,'figure.figsize':(8, 6)})
```

### 1. Simple Scatterplot

```
tips = sns.load_dataset("tips")   #  load the embedded  dataset

# Draw a simple scatter plot between two variables
sns.scatterplot(x="total_bill", y="tip", data=tips,s = 80)
```

![](/files/-MCYUWvBvnIXryK1anbB)

### 2. Differentiate groups by color

```
fferentiate Groups by Color# Group by another variable and show the groups with different colors:
sns.scatterplot(x="total_bill", y="tip", hue="time", data=tips, s= 80)
```

![](/files/-MCYUm-Vnl85nTX3DO-0)

### 3. Differentiate groups by color and marker

```
# Show the grouping variable by varying both color and marker:
sns.scatterplot(x="total_bill", y="tip", hue="time", style="time", data=tips, s= 200)
```

![](/files/-MCYV-RkEy0Hke6MWSX0)

```
sns.relplot(x="total_bill", y="tip",
                 col="time", hue="day", style="day",
                 kind="scatter", data=tips)
```

![](/files/-MCYVC5L5Jlirata9C4h)

### 4. Categorical Scatterplot

The swarm plot can draw a categorical scatterplot with non-overlapping points. It gives a better representation of the distribution of values. In addition, it is also a good complement to a box or violin plot in cases where you want to show all observations along with some representation of the underlying distribution.

```
sns.swarmplot(x="day", y="tip", hue="time",
              palette=["r", "b", "y",'m'], data=  tips)
```

![](/files/-MCZ5ghp7VAVj8PfNAf0)

### 5. Differentiate the quantitative variable by size

```
# Load the example mpg dataset
mpg = sns.load_dataset("mpg")
```

```
sns.scatterplot(x="horsepower", y="mpg", size="weight", data=mpg)
```

![](/files/-MCYYCJMdS8y5tdICwWI)

### 6. Differentiate the quantitative variable by size and color

```
sns.scatterplot(x="horsepower", y="mpg", hue ='origin',size="weight", data=mpg)
```

![](/files/-MCYY5CG9xl7UkKG8Avw)

### 7. More complex

```
# Plot miles per gallon against horsepower with other semantics

sns.relplot(x="horsepower", y="mpg", hue="origin", size="weight",
            sizes=(40, 400), alpha=.7, palette="muted",
            height=6, data=mpg)
```

![](/files/-MCYXO4yFCGALmaRBfBw)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://vecco-insight.gitbook.io/crash-visualization/seaborn/untitled-4/4.4.1-scatter-plot.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
