Added MPL Pie Chart node.

This commit is contained in:
HowToSD
2025-02-25 13:18:05 -08:00
parent 47965bc771
commit d330efa71c
7 changed files with 98 additions and 1 deletions
+3
View File
@@ -12,6 +12,7 @@ from .modules.cda.py_kv_int_create import PyKvIntCreate
from .modules.cda.py_kv_string_create import PyKvStringCreate
from .modules.matplotlib.mpl_bar import MPLBar
from .modules.matplotlib.mpl_line import MPLLine
from .modules.matplotlib.mpl_pie_chart import MPLPieChart
from .modules.matplotlib.mpl_scatter import MPLScatter
from .modules.numpy_wrapper.numpy_float_create import NumpyFloatCreate
from .modules.numpy_wrapper.numpy_int_create import NumpyIntCreate
@@ -153,6 +154,7 @@ NODE_CLASS_MAPPINGS: Dict[str, Type[T]] = {
"CDATextCreate": CDATextCreate,
"MPLBar": MPLBar,
"MPLLine": MPLLine,
"MPLPieChart": MPLPieChart,
"MPLScatter": MPLScatter,
"NumpyFloatCreate": NumpyFloatCreate,
"NumpyIntCreate": NumpyIntCreate,
@@ -297,6 +299,7 @@ NODE_DISPLAY_NAME_MAPPINGS: Dict[str, str] = {
"CDATextCreate": "CDA Text Create",
"MPLBar": "MPL Bar Chart",
"MPLLine": "MPL Line Plot",
"MPLPieChart": "MPL Pie Chart",
"MPLScatter": "MPL Scatter Plot",
"NumpyFloatCreate": "Numpy Float Create",
"NumpyIntCreate": "Numpy Int Create",
Binary file not shown.

After

Width:  |  Height:  |  Size: 112 KiB

+24
View File
@@ -0,0 +1,24 @@
# M P L Pie Chart
:MPL Pie Chart
Generates a pie chart from a pandas DataFrame.
Below screenshot shows a workflow to generate a pie chart from categorical data.
![Pie chart](../images/pie_chart.png)
## Input
| Name | Data type |
|---|---|
| dataframe | DataFrame |
| label_column_name | String |
| data_column_name | String |
| title | String |
## Output
| Data type |
|---|
| Image |
<HR>
Category: Plot
ComfyUI Data Analysis Node Reference. © 2025 Hide Inada (HowToSD.com). All rights reserved.
+1
View File
@@ -131,6 +131,7 @@
## Plot
| Node | Description |
| --- | --- |
| [M P L Pie Chart](mpl_pie_chart.md) | :MPL Pie Chart |
| [MPL Bar Chart](mpl_bar.md) | Generates a bar chart from a Pandas DataFrame. |
| [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. |
+1
View File
@@ -0,0 +1 @@
{"last_node_id":23,"last_link_id":39,"nodes":[{"id":2,"type":"PandasCreate","pos":[2874.72607421875,520.831298828125],"size":[270.51373291015625,144.48915100097656],"flags":{},"order":0,"mode":0,"inputs":[],"outputs":[{"name":"DATAFRAME","type":"DATAFRAME","links":[1],"slot_index":0}],"properties":{"Node name for S&R":"PandasCreate"},"widgets_values":["Fruits\napple\napple\napple\nbanana\nbanana\ncoconut"]},{"id":1,"type":"PandasValueCounts","pos":[2878.360107421875,709.3477172851562],"size":[269.8277587890625,66.52304077148438],"flags":{},"order":1,"mode":0,"inputs":[{"name":"dataframe","type":"DATAFRAME","link":1}],"outputs":[{"name":"DATAFRAME","type":"DATAFRAME","links":[2,38],"slot_index":0}],"properties":{"Node name for S&R":"PandasValueCounts"},"widgets_values":["Fruits"]},{"id":23,"type":"PreviewImage","pos":[3220.225341796875,853.7537841796875],"size":[470.0382995605469,449.1227722167969],"flags":{},"order":4,"mode":0,"inputs":[{"name":"images","type":"IMAGE","link":39}],"outputs":[],"properties":{"Node name for S&R":"PreviewImage"}},{"id":22,"type":"MPLPieChart","pos":[2881.26220703125,852.089111328125],"size":[263.0093688964844,109.4092025756836],"flags":{},"order":3,"mode":0,"inputs":[{"name":"dataframe","type":"DATAFRAME","link":38}],"outputs":[{"name":"IMAGE","type":"IMAGE","links":[39],"slot_index":0}],"properties":{"Node name for S&R":"MPLPieChart"},"widgets_values":["Fruits","count","Fruit distribution"]},{"id":3,"type":"PandasShowDataFrame","pos":[3227.885498046875,700.7517700195312],"size":[210,107.45079040527344],"flags":{},"order":2,"mode":0,"inputs":[{"name":"dataframe","type":"DATAFRAME","link":2}],"outputs":[{"name":"STRING","type":"STRING","links":null,"shape":6}],"properties":{"Node name for S&R":"PandasShowDataFrame"},"widgets_values":[" Fruits count\n0 apple 3\n1 banana 2\n2 coconut 1"]}],"links":[[1,2,0,1,0,"DATAFRAME"],[2,1,0,3,0,"DATAFRAME"],[38,1,0,22,0,"DATAFRAME"],[39,22,0,23,0,"IMAGE"]],"groups":[],"config":{},"extra":{"ds":{"scale":0.9777396879878871,"offset":[-2464.9461010126247,-450.0436961304677]},"node_versions":{"data-analysis":"bebf4760bc61e4ce5326061b2f56e96c2c9f5d60","comfy-core":"v0.3.10-40-gd0f3752"},"ue_links":[]},"version":0.4}
+68
View File
@@ -0,0 +1,68 @@
from typing import Any, Dict
from matplotlib import pyplot as plt
import pandas as pd
from .util import plot_post_steps
class MPLPieChart:
"""
:MPL Pie Chart
Generates a pie chart from a pandas DataFrame.
Below screenshot shows a workflow to generate a pie chart from categorical data.
![Pie chart](../images/pie_chart.png)
category: Plot
"""
@classmethod
def INPUT_TYPES(cls) -> Dict[str, Any]:
"""
Defines the input types for the `line_plot` function.
Returns:
Dict[str, Any]: A dictionary specifying required input types.
"""
return {
"required": {
"dataframe": ("DATAFRAME", {}),
"label_column_name": ("STRING", {"default": ""}),
"data_column_name": ("STRING", {"default": ""}),
"title": ("STRING", {"default": ""})
}
}
RETURN_TYPES: tuple = ("IMAGE",)
FUNCTION: str = "f"
CATEGORY: str = "Data Analysis"
def f(self,
dataframe: pd.DataFrame,
label_column_name: str,
data_column_name: str,
title: str) -> tuple:
"""
Generates a pie chart from a Pandas DataFrame.
Args:
dataframe (DataFrame): The DataFrame.
label_column_name (str): The column name for the labels.
data_column_name (str): The column name for the data.
title (str): The title of the plot.
Returns:
tuple: A tuple containing the image tensor representation of the plot.
"""
df = dataframe
# Create the plot
fig, ax = plt.subplots()
ax.pie(df[data_column_name], labels=df[label_column_name], autopct='%1.1f%%', startangle=140)
return plot_post_steps(
fig,
ax,
plt,
title,
"",
"",
False)
+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.4"
version = "1.3.5"
license = {file = "LICENSE"}
[project.urls]