Histograms

Draw one histogram of the DataFrame’s columns, or single histogram for Series

A histogram is a representation of the distribution of data. This function groups the values of all given Series in the DataFrame into bins

Examples

Histogram of a Column in a DataFrame

In the example below, we use the titanic dataset, to show a close to a 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">
<!--danfojs CDN -->
<script src="https://cdn.jsdelivr.net/npm/danfojs@0.1.2/dist/index.min.js"></script>
<title>Document</title>
</head>
<body>
<div id="plot_div"></div>
<script>
dfd.read_csv("https://raw.githubusercontent.com/pandas-dev/pandas/master/doc/data/titanic.csv")
.then(df => {
df['Age'].plot("plot_div").hist()
}).catch(err => {
console.log(err);
})
</script>
</body>
</html>

Customized Histogram plots on DataFrame

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!--danfojs CDN -->
<script src="https://cdn.jsdelivr.net/npm/danfojs@0.1.2/dist/index.min.js"></script>
<title>Document</title>
</head>
<body>
<div id="plot_div"></div>
<script>
dfd.read_csv("https://raw.githubusercontent.com/pandas-dev/pandas/master/doc/data/titanic.csv")
.then(df => {
var layout = {
bargap: 0,
bargroupgap: 0.1,
barmode: "stack",
title: "Histogram of two columns stacked",
xaxis: { title: "Value" },
yaxis: { title: "Count" }
}
sub_df = df.loc({ columns: ["Fare", "Age"] })
sub_df.plot("plot_div").hist({layout: layout })
}).catch(err => {
console.log(err);
})
</script>
</body>
</html>

Configuring your plots

danfo.js plotting uses Plotly.js as its backend for plotting. This means you have all the configuration, flexibility and interactiveness of Plotly.

All customization on the plot can be passed as an object of key-value pairs to the config parameter. For example:

var layout = {
title: 'A sample plot',
xaxis: {
title: 'X',
},
yaxis: {
title: 'Y',
}
}
df.plot("div_tag").histogram({layout: layout})

For more configuration options for Histograms, see the Plotly style doc.