coniston/double_y.py
2024-07-07 18:53:08 -04:00

44 lines
2.6 KiB
Python

import pandas as pd
import plotly.graph_objects as go
from plotly.subplots import make_subplots
# Load the data (assuming you've already loaded and processed it as shown)
data = pd.read_csv('06-25_07-07.csv')
# Calculation of Q (BTU / lb)
data['Q (BTU/lb)'] = data['Sewer Water Out'] - data['Sewer Water In']
# Convert 'Date/Time (--4:0:0)' column to datetime
data['Date/Time (--4:0:0)'] = pd.to_datetime(data['Date/Time (--4:0:0)'])
# Apply a smoothing function (moving average)
window_size = 10
data['Sewer Water In Smooth'] = data['Sewer Water In'].rolling(window=window_size, center=True).mean()
data['Sewer Water Out Smooth'] = data['Sewer Water Out'].rolling(window=window_size, center=True).mean()
data['Return Air Smooth'] = data['Return Air'].rolling(window=window_size, center=True).mean()
data['Supply Air Smooth'] = data['Supply Air'].rolling(window=window_size, center=True).mean()
data['Q Smooth'] = data['Q (BTU/lb)'].rolling(window=window_size, center=True).mean()
fig = make_subplots(rows=1, cols=1, shared_xaxes=True, vertical_spacing=0.1,
subplot_titles=(f'Temperature Variations and Transferred Heat from 25/06/2024-07/07/2024',),
specs=[[{"secondary_y": True}]])
fig.add_trace(go.Scatter(x=data['Date/Time (--4:0:0)'], y=data['Sewer Water In Smooth'], mode='lines', name='Sewer Water In',
line=dict(shape='spline', color='blue', width=4, dash='solid')), secondary_y=False)
fig.add_trace(go.Scatter(x=data['Date/Time (--4:0:0)'], y=data['Sewer Water Out Smooth'], mode='lines', name='Sewer Water Out',
line=dict(shape='spline', color='red', width=4, dash='solid')), secondary_y=False)
fig.add_trace(go.Scatter(x=data['Date/Time (--4:0:0)'], y=data['Return Air Smooth'], mode='lines', name='Return Air',
line=dict(shape='spline', color='orange', width=4, dash='solid')), secondary_y=False)
fig.add_trace(go.Scatter(x=data['Date/Time (--4:0:0)'], y=data['Supply Air Smooth'], mode='lines', name='Supply Air',
line=dict(shape='spline', color='green', width=4, dash='solid')), secondary_y=False)
fig.add_trace(go.Scatter(x=data['Date/Time (--4:0:0)'], y=data['Q Smooth'], mode='lines', name='Transferred Heat (BTU/lb)',
line=dict(shape='spline', color='purple', width=4, dash='solid')), secondary_y=True)
# Update layout
fig.update_layout(
xaxis_title='Date/Time',
yaxis_title='Temperature (F)',
legend_title_text='Legend',
font=dict(size=14),
width=1400,
height=800
)
# Save the plot (requires kaleido package)
fig.write_image('plotly_plot_with_q.png')