Comment on page
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.
In the example below, we use the titanic dataset, to show a close to real-world use case of danfo.js
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/lib/bundle.min.js"></script>
<title>Document</title>
</head>
<body>
<div id="plot_div"></div>
<script>
dfd.readCSV("https://raw.githubusercontent.com/pandas-dev/pandas/master/doc/data/titanic.csv")
.then(df => {
df.plot("plot_div").scatter({
config: { x: "Age", y: "Fare" }
})
}).catch(err => {
console.log(err);
})
</script>
</body>
</html>
.png?alt=media)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/lib/bundle.min.js"></script>
<title>Document</title>
</head>
<body>
<div id="plot_div"></div>
<script>
dfd.readCSV("https://raw.githubusercontent.com/pandas-dev/pandas/master/doc/data/titanic.csv")
.then(df => {
sub_df = df.loc({
config: {
columns: ["Age", "Fare", "Parch", "SibSp"]
}
})
sub_df.plot("plot_div").scatter()
}).catch(err => {
console.log(err);
})
</script>
</body>
</html>
.png?alt=media&token=295b1574-0817-492c-96fb-22771a24994b)
Last modified 1yr ago