-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvisualise_SIM.py
More file actions
145 lines (122 loc) · 4.25 KB
/
visualise_SIM.py
File metadata and controls
145 lines (122 loc) · 4.25 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import pandas as pd
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
# Read the CSV file
df = pd.read_csv('simulation_metrics.csv')
import pandas as pd
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
from scipy.ndimage import gaussian_filter
# Read the CSV file
df = pd.read_csv('simulation_metrics.csv')
# 1. Sim's 3D Location Density Plot
fig = plt.figure(figsize=(12, 10))
ax = fig.add_subplot(111, projection='3d')
# Create a 2D histogram
hist, x_edges, y_edges = np.histogram2d(df['x'], df['y'], bins=(50, 50))
# Apply Gaussian smoothing to the histogram
smoothed_hist = gaussian_filter(hist, sigma=1)
# Get the centers of the bins
x_centers = (x_edges[:-1] + x_edges[1:]) / 2
y_centers = (y_edges[:-1] + y_edges[1:]) / 2
# Create a meshgrid
X, Y = np.meshgrid(x_centers, y_centers)
# Flatten the arrays
x_flat = X.flatten()
y_flat = Y.flatten()
density_flat = smoothed_hist.T.flatten() # Transpose the histogram
# Remove zero density points
mask = density_flat > 0
x_plot = x_flat[mask]
y_plot = y_flat[mask]
density_plot = density_flat[mask]
# Normalize density for color mapping
norm = plt.Normalize(density_plot.min(), density_plot.max())
# Create the 3D scatter plot
scatter = ax.scatter(x_plot, y_plot, density_plot,
c=density_plot, cmap='viridis',
s=density_plot/density_plot.max()*100, # Adjust size scaling as needed
alpha=0.7, norm=norm)
# Add a color bar
cbar = fig.colorbar(scatter, shrink=0.5, aspect=5)
cbar.set_label('Activity Density', rotation=270, labelpad=15)
ax.set_title("Sim's 3D Location Density Plot")
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Density')
# Adjust the view angle for better visibility
ax.view_init(elev=30, azim=45)
plt.savefig('sim_3d_location_density_plot.png', dpi=300, bbox_inches='tight')
plt.close()
# 2. Financial Trends
plt.figure(figsize=(12, 6))
plt.plot(df['step'], df['money'])
plt.title("Sim's Financial Trend")
plt.xlabel('Steps')
plt.ylabel('Money')
plt.tight_layout()
plt.savefig('financial_trend.png')
plt.close()
# 3. Needs Over Time
needs = [col for col in df.columns if col.startswith('need_')]
plt.figure(figsize=(12, 6))
for need in needs:
plt.plot(df['step'], df[need], label=need.replace('need_', ''))
plt.title("Sim's Needs Over Time")
plt.xlabel('Steps')
plt.ylabel('Need Level')
plt.legend(loc='center left', bbox_to_anchor=(1, 0.5))
plt.tight_layout()
plt.savefig('needs_over_time.png')
plt.close()
# 4. Mood Distribution
plt.figure(figsize=(8, 6))
df['mood'].value_counts().plot(kind='bar')
plt.title("Distribution of Sim's Moods")
plt.xlabel('Mood')
plt.ylabel('Frequency')
plt.tight_layout()
plt.savefig('mood_distribution.png')
plt.close()
# 5. Market Trends
market_items = set([col.split('_')[1] for col in df.columns if col.startswith('market_') and col.endswith('_price')])
for item in market_items:
plt.figure(figsize=(12, 6))
plt.plot(df['step'], df[f'market_{item}_price'], label='Price')
plt.plot(df['step'], df[f'market_{item}_quantity'], label='Quantity')
plt.title(f"Market Trends for {item}")
plt.xlabel('Steps')
plt.ylabel('Value')
plt.legend()
plt.tight_layout()
plt.savefig(f'market_trends.png')
plt.close()
# 6. Activity Duration Distribution
plt.figure(figsize=(10, 6))
df['activity_duration'].hist(bins=20)
plt.title("Distribution of Activity Durations")
plt.xlabel('Duration')
plt.ylabel('Frequency')
plt.tight_layout()
plt.savefig('activity_duration_distribution.png')
plt.close()
# 7. 3D Trajectory Plot
fig = plt.figure(figsize=(12, 8))
ax = fig.add_subplot(111, projection='3d')
ax.plot(df['x'], df['y'], df['step'])
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Steps')
ax.set_title("Sim's 3D Trajectory Over Time")
plt.tight_layout()
plt.savefig('sim_3d_trajectory.png')
plt.close()
print("Visualization complete. Check the following files in the current directory:")
print("needs_over_time.png")
print("mood_distribution.png")
print("market_trends.png")
print("activity_duration_distribution.png")
print("sim_3d_trajectory.png")
print("sim_3d_location_density_plot.png")