Skip to content

Instantly share code, notes, and snippets.

@RenSys
Last active April 30, 2019 09:07
Show Gist options
  • Save RenSys/2e278c3e0c35fa9f2830749e374542c9 to your computer and use it in GitHub Desktop.
Save RenSys/2e278c3e0c35fa9f2830749e374542c9 to your computer and use it in GitHub Desktop.
Matplotlib - pd.Series dump to matplotlib png
from glob import glob
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
sns.set_style("darkgrid")
sns.set(rc = {"figure.figsize": (20, 10)})
sns.set(rc = {"figure.titlesize": "start-large"})
filename_wildcard = '*.gz'
df = pd.concat(
[pd.read_csv(fn, parse_dates = True, index_col = "timestamp") for fn in glob(filename_wildcard)],
sort = True,
)
# df = df[tags]
df.sort_index(inplace = True)
from glob import glob
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
sns.set_style("darkgrid")
sns.set(rc = {"figure.figsize": (20, 10)})
filename_wildcard = '*.gz'
df = pd.concat(
[pd.read_csv(fn, parse_dates = True, index_col = "timestamp") for fn in glob(filename_wildcard)],
sort = True,
)
df.sort_index(inplace = True)
_30_mins = 1_800
min_value_count = 1000
tag = '01_dv_01_si_daca_pv'
threshold = 2
first, last = 0, -1
sub_direction = 'diagrams'
diagram_prefix = '01'
for idx, (start, end) in enumerate(zip(range(0, len(df), _30_mins), range(_30_mins, len(df), _30_mins))):
plt.figure()
ax = None
data = df[tag].iloc[start:end]
if len(data[data > threshold]) > min_value_count:
start_time = str(df.iloc[start:end].index[first])
end_time = str(df.iloc[start:end].index[last])
ax = (df[tag].iloc[start:end].plot(title =
f'Figure {idx} \n Start: {start_time} \n End: {end_time}'))
ax.title.set_size(18)
ax.set_xlabel("Time (1 second Samples)")
ax.set_ylabel("DV01 Speed RPM")
start_time_str = start_time.replace('-', '_').replace(':', '_')
end_time_str = end_time.replace('-', '_').replace(':', '_')
plt.savefig(f'{sub_direction}/week_{diagram_prefix}_fig_{idx}_start_{start_time_str}_end_{end_time_str}.png')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment