Skip to content

Commit

Permalink
fix: Fixing box diagram output
Browse files Browse the repository at this point in the history
  • Loading branch information
brotherzhafif committed Oct 14, 2024
1 parent a0baa0d commit 435ece5
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
15 changes: 12 additions & 3 deletions Chart.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Chart.py
import matplotlib.pyplot as plt
import numpy as np
from matplotlib_venn import venn2, venn3

class Chart:
Expand All @@ -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.
Expand Down
15 changes: 15 additions & 0 deletions Main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# EXAMPLE PROGRAM
import FrequencyTable as ft
import Chart as ct
import pandas as pd
import tabulate as tabulate

Expand Down Expand Up @@ -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()
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
### Required
- Matplotlib
- Matplotlib_Venn
- Seaborn
- Numpy
- Tabulate
- Pandas
Expand Down

0 comments on commit 435ece5

Please sign in to comment.