Scatter Plots
Create a scatter plot of columns in a DataFrame
The coordinates of each point are defined by two DataFrame columns and filled circles are used to represent each point. Scatter plot is useful for visualizing complex correlations between two variables.

Examples

Scatter Plots on Columns in a DataFrame

In the example below, we use the titanic dataset, to show a close to real-world use case of danfo.js
1
<!DOCTYPE html>
2
<html lang="en">
3
4
<head>
5
<meta charset="UTF-8">
6
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7
<script src="https://cdn.plot.ly/plotly-1.2.0.min.js"></script>
8
<script src="https://cdn.jsdelivr.net/npm/[email protected]/lib/bundle.min.js"></script>
9
<title>Document</title>
10
</head>
11
12
<body>
13
14
<div id="plot_div"></div>
15
<script>
16
17
dfd.read_csv("https://raw.githubusercontent.com/pandas-dev/pandas/master/doc/data/titanic.csv")
18
.then(df => {
19
20
df.plot("plot_div").scatter({ x: "Age", y: "Fare" })
21
22
}).catch(err => {
23
console.log(err);
24
})
25
26
</script>
27
</body>
28
29
</html>
Copied!

More Examples

1
<!DOCTYPE html>
2
<html lang="en">
3
4
<head>
5
<meta charset="UTF-8">
6
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7
<script src="https://cdn.plot.ly/plotly-1.2.0.min.js"></script>
8
<script src="https://cdn.jsdelivr.net/npm/[email protected]/lib/bundle.min.js"></script>
9
<title>Document</title>
10
</head>
11
12
<body>
13
14
<div id="plot_div"></div>
15
<script>
16
17
dfd.read_csv("https://raw.githubusercontent.com/pandas-dev/pandas/master/doc/data/titanic.csv")
18
.then(df => {
19
20
sub_df = df.loc({columns: ["Age", "Fare", "Parch", "SibSp"]})
21
sub_df.plot("plot_div").scatter()
22
23
}).catch(err => {
24
console.log(err);
25
})
26
27
</script>
28
</body>
29
30
</html>
Copied!
To set configuration for your plots, see the Configuring your plot page
Last modified 17d ago