mirror of
https://github.com/gsi-upm/soil
synced 2024-11-22 03:02:28 +00:00
Plot env without agent reporters
This commit is contained in:
parent
93d23e4cab
commit
d13e4eb4b9
@ -1,12 +1,11 @@
|
|||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
import sqlalchemy
|
import sqlalchemy
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
|
|
||||||
def plot(env, agent_df=None, model_df=None, steps=False, ignore=["agent_count", ]):
|
def plot(env, agent_df=None, model_df=None, steps=False, ignore=["agent_count", ]):
|
||||||
"""Plot the model dataframe and agent dataframe together."""
|
"""Plot the model dataframe and agent dataframe together."""
|
||||||
if agent_df is None:
|
|
||||||
agent_df = env.agent_df()
|
|
||||||
if model_df is None:
|
if model_df is None:
|
||||||
model_df = env.model_df()
|
model_df = env.model_df()
|
||||||
ignore = list(ignore)
|
ignore = list(ignore)
|
||||||
@ -16,10 +15,16 @@ def plot(env, agent_df=None, model_df=None, steps=False, ignore=["agent_count",
|
|||||||
ignore.append("time")
|
ignore.append("time")
|
||||||
|
|
||||||
ax = model_df.drop(ignore, axis='columns').plot();
|
ax = model_df.drop(ignore, axis='columns').plot();
|
||||||
if not agent_df.empty:
|
if agent_df is None:
|
||||||
|
try:
|
||||||
|
agent_df = env.agent_df()
|
||||||
|
except UserWarning:
|
||||||
|
print("No agent dataframe provided and no agent reporters found. Skipping agent plot.", file=sys.stderr)
|
||||||
|
return
|
||||||
agent_df.unstack().apply(lambda x: x.value_counts(),
|
agent_df.unstack().apply(lambda x: x.value_counts(),
|
||||||
axis=1).fillna(0).plot(ax=ax, secondary_y=True);
|
axis=1).fillna(0).plot(ax=ax, secondary_y=True);
|
||||||
|
|
||||||
|
|
||||||
Results = namedtuple("Results", ["config", "parameters", "env", "agents"])
|
Results = namedtuple("Results", ["config", "parameters", "env", "agents"])
|
||||||
#TODO implement reading from CSV and SQLITE
|
#TODO implement reading from CSV and SQLITE
|
||||||
def read_sql(fpath=None, name=None, include_agents=False):
|
def read_sql(fpath=None, name=None, include_agents=False):
|
||||||
|
Loading…
Reference in New Issue
Block a user