Skip to content

feat: add standard histogram plot #85

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions docs/analysis_modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,53 @@ line.plot(
)
```

### Histogram Plot
<div class="clear" markdown>

![Image title](assets/images/analysis_modules/plots/histogram_plot.svg){ align=right loading=lazy width="50%"}

Histograms are particularly useful for visualizing the distribution of data, allowing you to see how values in one or more metrics are spread across different ranges. This module also supports grouping by categories, enabling you to compare the distributions across different groups. When grouping by a category, multiple histograms are generated on the same plot, allowing for easy comparison across categories.

Histograms are commonly used to analyze:

- Sales, revenue or other metric distributions
- Distribution of customer segments (e.g., by age, income)
- Comparing metric distributions across product categories

This module allows you to customize legends, axes, and other visual elements, as well as apply clipping or filtering on the data values to focus on specific ranges.

</div>

Example:

```python
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd

from pyretailscience.plots import histogram

df = pd.DataFrame({
'first_purchase_revenue': np.concatenate([
np.random.normal(70, 10, 50000),
np.random.normal(90, 15, 50000)
]),
'product': ['Product A'] * 50000 + ['Product B'] * 50000
})

histogram.plot(
df=df,
value_col='first_purchase_revenue',
group_col='product',
title="First Purchase Revenue by Product (£)",
x_label="Revenue (£)",
y_label="Number of Customers",
source_text="Source: PyRetailScience - 2024",
move_legend_outside=True,
use_hatch=True
)
```

### Waterfall Plot

<div class="clear" markdown>
Expand Down
3 changes: 3 additions & 0 deletions docs/api/plots/histogram.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Histogram Plot

::: pyretailscience.plots.histogram
Loading