Skip to content

Implementing a Boxplot #543

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

Open
smeingast opened this issue Mar 2, 2025 · 3 comments
Open

Implementing a Boxplot #543

smeingast opened this issue Mar 2, 2025 · 3 comments

Comments

@smeingast
Copy link

smeingast commented Mar 2, 2025

Hello everyone,
I am looking to replicate a boxplot visualization using the Plotly Graph Card in Home Assistant, similar to what I've achieved using Matplotlib and Seaborn. Below is the code I used to generate the plot:

import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
import numpy as np

# Set random seed for reproducibility
np.random.seed(42)

# Define days of the week
days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']

# Create varied capacity data for each day
capacity_means = {
    'Monday': 45,
    'Tuesday': 50,
    'Wednesday': 55,
    'Thursday': 60,
    'Friday': 65,
    'Saturday': 70,
    'Sunday': 75
}

# Generate data
data = []
for day in days:
    # Create a normal distribution for each day with different means
    day_data = np.random.normal(loc=capacity_means[day], scale=10, size=150)  # 150 samples per day
    data.extend(zip([day]*150, day_data))

# Create a DataFrame
df = pd.DataFrame(data, columns=['Day', 'Capacity'])

# Plotting
plt.figure(figsize=(10, 6))
sns.boxplot(x='Day', y='Capacity', data=df, order=days, showmeans=False,
            meanprops={"marker": "o", "markerfacecolor": "red", "markeredgecolor": "black", "markersize": "10"})

# Add labels and title
plt.title('Capacity Distribution by Day of the Week')
plt.xlabel('Day of the Week')
plt.ylabel('Capacity')
plt.legend()

# Show plot
plt.tight_layout()
plt.show()

Objective:
I want to display a similar boxplot in Home Assistant using the Plotly Graph Card. The plot should show:

  • Each day of the week on the x-axis.
  • Boxplots for each day with the capability to show mean/median and the 95th percentile.

Would this work with plotly graph card somehow?

Image

@dbuezas
Copy link
Owner

dbuezas commented Mar 2, 2025

There is type: box in plotly

@smeingast
Copy link
Author

There is type: box in plotly

Thanks!! I guess interested in understanding how to group data points effectively for visualization. Specifically, if I have a time series spanning several months, is it possible to create a box plot that groups all data points by each weekday? Additionally, could I group all data points for each of the 24 hours in a day?

@dbuezas
Copy link
Owner

dbuezas commented Mar 2, 2025

This example shows hot to group per week day

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants