Skip to content

Commit 435ece5

Browse files
committed
fix: Fixing box diagram output
1 parent a0baa0d commit 435ece5

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

Chart.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Chart.py
22
import matplotlib.pyplot as plt
3+
import numpy as np
34
from matplotlib_venn import venn2, venn3
45

56
class Chart:
@@ -22,11 +23,19 @@ def _apply_common_properties(self):
2223
if self.ylabel:
2324
plt.ylabel(self.ylabel)
2425

25-
def box(self, data):
26-
# Prepare a box diagram for visualizing the distribution of a dataset.
26+
def box(self, data, labels=None):
27+
# Prepare a bar chart to visualize the values in a box-like manner.
2728
self.figure = plt.figure(figsize=(10, 6))
28-
plt.boxplot(data)
29+
bar_width = 0.5 # Width of the bars
30+
indices = range(len(data)) # Indices for the bars
31+
32+
plt.bar(indices, data, width=bar_width, alpha=0.7, color='b')
33+
34+
if labels:
35+
plt.xticks(indices, labels) # Set the x-ticks to the provided labels
36+
2937
self._apply_common_properties()
38+
plt.grid(axis='y') # Add gridlines to the y-axis for better readability
3039

3140
def pie(self, data, labels):
3241
# Prepare a pie chart to show percentage distribution.

Main.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# EXAMPLE PROGRAM
22
import FrequencyTable as ft
3+
import Chart as ct
34
import pandas as pd
45
import tabulate as tabulate
56

@@ -69,3 +70,17 @@
6970
# print(tablesimple)
7071
print(tablegrouped)
7172

73+
74+
# Initialize the chart object with common properties
75+
chart = ct.Chart(title="Dataset Box Diagram", xlabel="Data", ylabel="Value")
76+
77+
# Prepare a box diagram
78+
chart.box(dataset)
79+
80+
# Display the prepared chart
81+
chart.show()
82+
83+
# Example for pie chart
84+
chart = ct.Chart(title="Grouped Frequency Pie Chart")
85+
chart.pie(data.grouped.frequency, labels=data.grouped.ranges)
86+
chart.show()

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
### Required
1111
- Matplotlib
1212
- Matplotlib_Venn
13-
- Seaborn
1413
- Numpy
1514
- Tabulate
1615
- Pandas

0 commit comments

Comments
 (0)