-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplotting.py
More file actions
36 lines (25 loc) · 1017 Bytes
/
plotting.py
File metadata and controls
36 lines (25 loc) · 1017 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# Plotting
# Use NumPy, Pandas, and MatplotLib to plot the data
import matplotlib.pyplot as plt
import pandas as pd
def plot_balance_trends(transaction_history):
if not transaction_history:
print("No transaction history available to plot.")
return
# Convert transaction history to a Pandas DataFrame
df = pd.DataFrame(transaction_history)
if "timestamp" not in df.columns or "balance" not in df.columns:
print("Transaction history is missing required fields ('timestamp' or 'balance').")
return
df["timestamp"] = pd.to_datetime(df["timestamp"])
df = df.sort_values(by="timestamp")
# Plot the data
plt.figure(figsize=(10, 6))
plt.plot(df["timestamp"], df["balance"], marker="o", linestyle="-", color="b")
plt.title("Balance Trends Over Time")
plt.xlabel("Timestamp")
plt.ylabel("Balance")
plt.grid(True)
plt.xticks(rotation=45)
plt.tight_layout()
plt.show()