Skip to content

Instantly share code, notes, and snippets.

@mitchute
Created April 27, 2020 20:22
Show Gist options
  • Save mitchute/0a47e1f060878d565aecf2897c09c149 to your computer and use it in GitHub Desktop.
Save mitchute/0a47e1f060878d565aecf2897c09c149 to your computer and use it in GitHub Desktop.
from textwrap import wrap
import matplotlib.pyplot as plt
import pandas as pd
def plot(base_path: str, mod_path: str, plot_vars=None):
"""
Plots the results from two eplusout.csv files. Attempts to match the columns names and plot these series together.
:param base_path: Path to the base simulation eplusout.csv file.
Typically this is the results from the 'develop' branch.
:param mod_path: Path to the modified simulation eplusout.csv file.
:param plot_vars: Python dict object containing mis-matched columns names to be plotted together.
Base columns names are the dict keys, and mod columns names are the values.
Example 1:
>>> base_path = "/path/to/base/eplusout.csv"
>>> mod_path = "/path/to/mod/eplusout.csv"
>>> plot(base_path, mod_path)
Example 2:
cols_to_plot = {"Base Col_1 Name": "Mod Col_1 Name", "Base Col_2 Name": "Mod Col_2 Name"}
>>> plot(base_path, mod_path, cols_to_plot)
"""
df_base = pd.read_csv(base_path)
df_mod = pd.read_csv(mod_path)
plot_vars_present = True
if plot_vars is None:
plot_vars_present = False
# strip whitespace
df_base.rename(columns=lambda x: x.strip(), inplace=True)
df_mod.rename(columns=lambda x: x.strip(), inplace=True)
# drop Date/Time
df_base.drop(labels="Date/Time", axis=1, inplace=True)
df_mod.drop(labels="Date/Time", axis=1, inplace=True)
if plot_vars is None:
base_cols = df_base.columns.to_list()
mod_cols = df_mod.columns.to_list()
plot_vars = dict()
base_skipped = list()
mod_skipped = list()
for col in base_cols:
if col in mod_cols:
plot_vars[col] = col
else:
base_skipped.append(col)
for col in mod_cols:
if col not in base_cols:
mod_skipped.append(col)
print(f"Columns Skipped from Base: {base_skipped}")
print(f"Columns Skpped from Mod: {mod_skipped}")
for idx, (base_col, mod_col) in enumerate(plot_vars.items()):
base = df_base[base_col]
mod = df_mod[mod_col]
diff = base - mod
fig, (ax1, ax2) = plt.subplots(2, sharex=True)
if plot_vars_present:
ax1.plot(base, label=base_col)
ax1.plot(mod, label=mod_col, linestyle='--')
else:
ax1.plot(base, label='EMS')
ax1.plot(mod, label='Python', linestyle='--')
ax1.legend()
ax1.grid()
ax2.plot(diff)
ax2.set_ylabel("Delta (EMS - Python)")
ax2.grid()
if not plot_vars_present:
plt.suptitle("\n".join(wrap(base_col)))
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment