Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,6 +8,8 @@ from plotly.subplots import make_subplots
|
|
| 8 |
import plotly.express as px
|
| 9 |
import datetime
|
| 10 |
import numpy as np
|
|
|
|
|
|
|
| 11 |
|
| 12 |
# Function to fetch renewable energy data
|
| 13 |
def get_renewable_energy_data(city_code):
|
|
@@ -244,6 +246,13 @@ if st.button('Calculate Optimal Energy Mix'):
|
|
| 244 |
hourly_data['Hour'] = hourly_data['Time'].dt.hour
|
| 245 |
|
| 246 |
for column in hourly_data.columns[2:]:
|
|
|
|
| 247 |
pivot_df = hourly_data.pivot_table(index='Hour', columns='Date', values=column, aggfunc=np.mean)
|
| 248 |
-
|
| 249 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
import plotly.express as px
|
| 9 |
import datetime
|
| 10 |
import numpy as np
|
| 11 |
+
import matplotlib.pyplot as plt
|
| 12 |
+
import seaborn as sns
|
| 13 |
|
| 14 |
# Function to fetch renewable energy data
|
| 15 |
def get_renewable_energy_data(city_code):
|
|
|
|
| 246 |
hourly_data['Hour'] = hourly_data['Time'].dt.hour
|
| 247 |
|
| 248 |
for column in hourly_data.columns[2:]:
|
| 249 |
+
# Create a pivot table to reshape data into hours of the day vs days of the year
|
| 250 |
pivot_df = hourly_data.pivot_table(index='Hour', columns='Date', values=column, aggfunc=np.mean)
|
| 251 |
+
# Plot using seaborn to create a heatmap similar to the provided image
|
| 252 |
+
plt.figure(figsize=(12, 6))
|
| 253 |
+
sns.heatmap(pivot_df, cmap='viridis', cbar_kws={'label': f'{column} (kW)'})
|
| 254 |
+
plt.title(f'Heatmap of {column}')
|
| 255 |
+
plt.xlabel('Days of the Year')
|
| 256 |
+
plt.ylabel('Hours of the Day')
|
| 257 |
+
st.pyplot(plt.gcf())
|
| 258 |
+
plt.close()
|