From 435ece5b6df6af7d6a6aba98ee59e9c95c21fa18 Mon Sep 17 00:00:00 2001 From: brotherzhafif Date: Mon, 14 Oct 2024 19:59:29 +0700 Subject: [PATCH] fix: Fixing box diagram output --- Chart.py | 15 ++++++++++++--- Main.py | 15 +++++++++++++++ README.md | 1 - 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/Chart.py b/Chart.py index d3407fe..3d048f5 100644 --- a/Chart.py +++ b/Chart.py @@ -1,5 +1,6 @@ # Chart.py import matplotlib.pyplot as plt +import numpy as np from matplotlib_venn import venn2, venn3 class Chart: @@ -22,11 +23,19 @@ def _apply_common_properties(self): if self.ylabel: plt.ylabel(self.ylabel) - def box(self, data): - # Prepare a box diagram for visualizing the distribution of a dataset. + def box(self, data, labels=None): + # Prepare a bar chart to visualize the values in a box-like manner. self.figure = plt.figure(figsize=(10, 6)) - plt.boxplot(data) + bar_width = 0.5 # Width of the bars + indices = range(len(data)) # Indices for the bars + + plt.bar(indices, data, width=bar_width, alpha=0.7, color='b') + + if labels: + plt.xticks(indices, labels) # Set the x-ticks to the provided labels + self._apply_common_properties() + plt.grid(axis='y') # Add gridlines to the y-axis for better readability def pie(self, data, labels): # Prepare a pie chart to show percentage distribution. diff --git a/Main.py b/Main.py index 6c344e9..7067f0b 100644 --- a/Main.py +++ b/Main.py @@ -1,5 +1,6 @@ # EXAMPLE PROGRAM import FrequencyTable as ft +import Chart as ct import pandas as pd import tabulate as tabulate @@ -69,3 +70,17 @@ # print(tablesimple) print(tablegrouped) + +# Initialize the chart object with common properties +chart = ct.Chart(title="Dataset Box Diagram", xlabel="Data", ylabel="Value") + +# Prepare a box diagram +chart.box(dataset) + +# Display the prepared chart +chart.show() + +# Example for pie chart +chart = ct.Chart(title="Grouped Frequency Pie Chart") +chart.pie(data.grouped.frequency, labels=data.grouped.ranges) +chart.show() \ No newline at end of file diff --git a/README.md b/README.md index beca984..22656be 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,6 @@ ### Required - Matplotlib - Matplotlib_Venn -- Seaborn - Numpy - Tabulate - Pandas