Added SNS Boxplot node

This commit is contained in:
HowToSD
2025-02-25 15:40:01 -08:00
parent d330efa71c
commit 0316f8949b
6 changed files with 148 additions and 1 deletions
+3
View File
@@ -133,6 +133,7 @@ from .modules.pytorch_wrapper.pt_to_latent import PtToLatent
from .modules.pytorch_wrapper.pt_to_numpy import PtToNumpy
from .modules.pytorch_wrapper.pt_to_rgb_tensors import PtToRgbTensors
from .modules.seaborn_wrapper.sns_bar import SNSBar
from .modules.seaborn_wrapper.sns_boxplot import SNSBoxplot
from .modules.seaborn_wrapper.sns_histogram import SNSHistogram
from .modules.seaborn_wrapper.sns_line import SNSLine
from .modules.seaborn_wrapper.sns_scatter import SNSScatter
@@ -278,6 +279,7 @@ NODE_CLASS_MAPPINGS: Dict[str, Type[T]] = {
"PyKvIntCreate": PyKvIntCreate,
"PyKvStringCreate": PyKvStringCreate,
"SNSBar": SNSBar,
"SNSBoxplot": SNSBoxplot,
"SNSHistogram": SNSHistogram,
"SNSLine": SNSLine,
"SNSScatter": SNSScatter,
@@ -423,6 +425,7 @@ NODE_DISPLAY_NAME_MAPPINGS: Dict[str, str] = {
"PyKvIntCreate": "Py Kv Int Create",
"PyKvStringCreate": "Py Kv String Create",
"SNSBar": "SNS Bar Chart",
"SNSBoxplot": "SNS Boxplot",
"SNSHistogram": "SNS Histogram",
"SNSLine": "SNS Line Plot",
"SNSScatter": "SNS Scatter Plot",
Binary file not shown.

After

Width:  |  Height:  |  Size: 137 KiB

+1
View File
@@ -136,6 +136,7 @@
| [MPL Line Plot](mpl_line.md) | Generates a line plot from a pandas DataFrame. |
| [MPL Scatter Plot](mpl_scatter.md) | Generates a scatter plot from a pandas DataFrame. |
| [SNS Bar Chart](sns_bar.md) | Generates a bar chart from a Pandas DataFrame using Seaborn. |
| [SNS Boxplot](sns_boxplot.md) | Generates a boxplot from a Pandas DataFrame using Seaborn. |
| [SNS Histogram](sns_histogram.md) | Generates a histogram from a Pandas DataFrame using Seaborn. |
| [SNS Line Plot](sns_line.md) | Generates a line plot from a pandas DataFrame using Seaborn. |
| [SNS Scatter Plot](sns_scatter.md) | Generates a scatter plot from a pandas DataFrame using Seaborn. |
+44
View File
@@ -0,0 +1,44 @@
# SNS Boxplot
Generates a boxplot from a Pandas DataFrame using Seaborn.
You can generate a boxplot from either a single column or two columns.
* For two columns, the first column should contain the category, and the second column should contain the corresponding numerical values.
* For a wide-format table, use the Pandas Melt node to create a category column first. This column is referred to as the "variable" column in melting.
* For a single-column dataset, leave the category field blank.
For example, if you have a DataFrame tracking apple and banana prices at various stores:
```
Fruit Price
apple 5
apple 3
apple 2
appel 2.5
banana 4
banana 2
banana 2
```
If you specify `Fruit` as the category and `Price` as the value, two boxplots will be generated: one for apples and one for bananas.
![Boxplot](../images/boxplot.png)
Refer to [Seaborn documentation](https://seaborn.pydata.org/generated/seaborn.boxplot.html) for more information.
## Input
| Name | Data type |
|---|---|
| dataframe | DataFrame |
| category_column_name | String |
| value_column_name | String |
| title | String |
| style | String |
| palette | String |
## Output
| Data type |
|---|
| Image |
<HR>
Category: Plot
ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved.
+99
View File
@@ -0,0 +1,99 @@
from typing import Any, Dict
from matplotlib import pyplot as plt
import pandas as pd
import seaborn as sns
from .util import plot_post_steps
from .util import set_up_sns_style_palette
class SNSBoxplot:
"""
SNS Boxplot:
Generates a boxplot from a Pandas DataFrame using Seaborn.
You can generate a boxplot from either a single column or two columns.
* For two columns, the first column should contain the category, and the second column should contain the corresponding numerical values.
* For a wide-format table, use the Pandas Melt node to create a category column first. This column is referred to as the "variable" column in melting.
* For a single-column dataset, leave the category field blank.
For example, if you have a DataFrame tracking apple and banana prices at various stores:
```
Fruit Price
apple 5
apple 3
apple 2
appel 2.5
banana 4
banana 2
banana 2
```
If you specify `Fruit` as the category and `Price` as the value, two boxplots will be generated: one for apples and one for bananas.
![Boxplot](../images/boxplot.png)
Refer to [Seaborn documentation](https://seaborn.pydata.org/generated/seaborn.boxplot.html) for more information.
category: Plot
"""
@classmethod
def INPUT_TYPES(cls) -> Dict[str, Any]:
"""
Defines the input types for the `bar_chart` function.
Returns:
Dict[str, Any]: A dictionary specifying required input types.
"""
return {
"required": {
"dataframe": ("DATAFRAME", {}),
"category_column_name": ("STRING", {"default": ""}),
"value_column_name": ("STRING", {"default": ""}),
"title": ("STRING", {"default": ""}),
"style": ("STRING", {"default": ""}),
"palette": ("STRING", {"default": ""})
}
}
RETURN_TYPES: tuple = ("IMAGE",)
FUNCTION: str = "f"
CATEGORY: str = "Data Analysis"
def f(self,
dataframe: pd.DataFrame,
category_column_name: str,
value_column_name: str,
title: str,
style: str=None,
palette: str=None) -> tuple:
"""
Generates a bar chart from a pandas DataFrame.
Args:
dataframe (DataFrame): The DataFrame.
category_column_name (str): The category (variable) column name.
value_column_name (str): The column name for the value data.
title (str): The title of the plot.
style (str): Style of the plot
palette (str): Palette of the plot
Returns:
tuple: A tuple containing the image tensor representation of the plot.
"""
df = dataframe
set_up_sns_style_palette(style, palette)
# Create the plot
fig, ax = plt.subplots()
if category_column_name:
sns.boxplot(x=df[category_column_name],y=df[value_column_name], ax=ax)
else:
sns.boxplot(y=df[value_column_name], ax=ax)
return plot_post_steps(
fig,
ax,
plt,
title,
None,
None,
None)
+1 -1
View File
@@ -1,7 +1,7 @@
[project]
name = "data-analysis"
description = "Data analysis custom modules for ComfyUI - Use Pandas & Matplotlib within ComfyUI"
version = "1.3.5"
version = "1.3.6"
license = {file = "LICENSE"}
[project.urls]