Update app.py
Browse files
app.py
CHANGED
|
@@ -99,22 +99,34 @@ def classify_plate_color(plate_img):
|
|
| 99 |
def get_dashboard():
|
| 100 |
df = pd.read_sql("SELECT * FROM vehicles", conn)
|
| 101 |
|
| 102 |
-
fig, ax = plt.subplots(figsize=(
|
| 103 |
|
| 104 |
if len(df) == 0:
|
| 105 |
ax.text(0.5, 0.5, "No vehicles scanned yet",
|
| 106 |
-
ha="center", va="center", fontsize=
|
| 107 |
ax.axis("off")
|
| 108 |
return fig
|
| 109 |
|
| 110 |
counts = df["type"].value_counts()
|
| 111 |
-
counts.plot(kind="line", ax=ax)
|
| 112 |
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
ax.set_ylabel("Count")
|
| 116 |
-
ax.grid(axis="y")
|
| 117 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
return fig
|
| 119 |
|
| 120 |
|
|
|
|
| 99 |
def get_dashboard():
|
| 100 |
df = pd.read_sql("SELECT * FROM vehicles", conn)
|
| 101 |
|
| 102 |
+
fig, ax = plt.subplots(figsize=(7, 5))
|
| 103 |
|
| 104 |
if len(df) == 0:
|
| 105 |
ax.text(0.5, 0.5, "No vehicles scanned yet",
|
| 106 |
+
ha="center", va="center", fontsize=12)
|
| 107 |
ax.axis("off")
|
| 108 |
return fig
|
| 109 |
|
| 110 |
counts = df["type"].value_counts()
|
|
|
|
| 111 |
|
| 112 |
+
# Use bar chart instead of line for categorical data
|
| 113 |
+
counts.plot(kind="bar", ax=ax, color="steelblue")
|
|
|
|
|
|
|
| 114 |
|
| 115 |
+
ax.set_title("Vehicle Classification Dashboard", fontsize=12)
|
| 116 |
+
ax.set_xlabel("Vehicle Type", fontsize=10)
|
| 117 |
+
ax.set_ylabel("Count", fontsize=10)
|
| 118 |
+
|
| 119 |
+
# Ensure labels are fully visible
|
| 120 |
+
ax.set_xticks(range(len(counts.index)))
|
| 121 |
+
ax.set_xticklabels(counts.index, rotation=0, ha="center")
|
| 122 |
+
|
| 123 |
+
ax.grid(axis="y", linestyle="--", alpha=0.6)
|
| 124 |
+
|
| 125 |
+
# Add value labels on top of bars
|
| 126 |
+
for i, v in enumerate(counts.values):
|
| 127 |
+
ax.text(i, v + 0.05, str(v), ha="center", va="bottom", fontsize=10)
|
| 128 |
+
|
| 129 |
+
plt.tight_layout()
|
| 130 |
return fig
|
| 131 |
|
| 132 |
|