add boxplot

This commit is contained in:
Youngjoon Lee 2024-05-28 13:48:56 +09:00
parent ba22e3529a
commit a7433cbf4e
No known key found for this signature in database
GPG Key ID: 09B750B5BD6F08A2
1 changed files with 19 additions and 6 deletions

View File

@ -96,10 +96,11 @@ class Analysis:
if not df.empty:
dataframes.append(df)
df = pd.concat(dataframes, ignore_index=True)
df_pivot = df.pivot(index="time", columns="node_id", values="msg_cnt")
msg_cnt_df = df.pivot(index="time", columns="node_id", values="msg_cnt")
plt.figure(figsize=(12, 6))
for column in df_pivot.columns:
plt.plot(df_pivot.index, df_pivot[column], marker=None, label=column)
for column in msg_cnt_df.columns:
plt.plot(msg_cnt_df.index, msg_cnt_df[column], marker=None, label=column)
plt.title("Messages in each node over time")
plt.xlabel("Time")
plt.ylabel("Msg Count")
@ -108,10 +109,10 @@ class Analysis:
plt.tight_layout()
plt.show()
df_pivot = df.pivot(index="time", columns="node_id", values="sender_cnt")
sender_cnt_df = df.pivot(index="time", columns="node_id", values="sender_cnt")
plt.figure(figsize=(12, 6))
for column in df_pivot.columns:
plt.plot(df_pivot.index, df_pivot[column], marker=None, label=column)
for column in sender_cnt_df.columns:
plt.plot(sender_cnt_df.index, sender_cnt_df[column], marker=None, label=column)
plt.title("Senders of messages in each node over time")
plt.xlabel("Time")
plt.ylabel("Sender Count")
@ -120,6 +121,18 @@ class Analysis:
plt.tight_layout()
plt.show()
plt.figure(figsize=(12, 6))
df.boxplot(column="sender_cnt", by="time", medianprops={"color": "red", "linewidth": 2.5})
plt.title("Distribution of senders of messages in each node over time")
plt.suptitle("")
plt.xticks([])
plt.xlabel("Time")
plt.ylabel("Sender Count")
plt.ylim(bottom=0)
plt.grid(axis="x")
plt.tight_layout()
plt.show()
def node_states(self):
rows = []
for time, node_states in self.sim.p2p.adversary.node_states.items():