Added plotting functions

This commit is contained in:
Khalim Conn-Kowlessar 2023-06-27 09:56:14 +01:00
parent 9adb03530e
commit 3faaa08b5c
5 changed files with 54 additions and 8 deletions

View file

@ -114,15 +114,10 @@ def handler():
for p in input_properties:
p.get_components(cleaner)
# TODO: Add property age band into this
uvalue_estimates = UvalueEstimations(data=data)
uvalue_estimates.get_estimates(cleaner=cleaner)
# Now, given the components, we want to idenfity upgrade options
import pandas as pd
floors_df = pd.DataFrame(
[{"address1": p.address1, **p.floor} for p in input_properties]
)
input_properties[4].data["address1"]
input_properties[4].data["postcode"]
floors_df["address1"].values[4]
@ -136,8 +131,15 @@ def handler():
df["property-type"].unique()
from model_data.recommendations.WallRecommendations import WallRecommendations
all_res = []
for p in input_properties:
inst = WallRecommendations(property_instance=p, uvalue_estimates=uvalue_estimates)
inst.recommend()
n_recs = len(inst.recommendations)
all_res.append(n_recs)
self = WallRecommendations(property_instance=input_properties[2], uvalue_estimates=uvalue_estimates)
input_properties[2].walls
input_properties[6].walls
self.recommend()
df = pd.DataFrame(self.recommendations[0]["parts"])
recommendations = pd.DataFrame(self.recommendations)

View file

View file

@ -0,0 +1,40 @@
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
def create_heatmap_plots(data, response_var, pivot_var1, pivot_var2, order1=None, order2=None):
"""
Create a heatmap plot based on a list of data and given variables.
:param data: List of dictionaries, input data.
:param response_var: String, response variable to be plotted.
:param pivot_var1: String, first pivot variable to be used in the plot.
:param pivot_var2: String, second pivot variable to be used in the plot.
:param order1: List, the order of categories for pivot_var1. Optional.
:param order2: List, the order of categories for pivot_var2. Optional.
Returns:
None. Displays the generated plot.
"""
# Create a DataFrame from your list of dictionaries
df = pd.DataFrame(data)
# Convert the response variable column to float type if it's not already
df[response_var] = df[response_var].astype(float)
# Create a pivot table
pivot = df.pivot_table(index=pivot_var1, columns=pivot_var2, values=response_var)
# If an order is provided, reorder the pivot table
if order1 is not None:
pivot = pivot.reindex(order1)
if order2 is not None:
pivot = pivot[order2]
# Plot the heatmap
plt.figure(figsize=(10, 6))
sns.heatmap(pivot, annot=True, fmt=".2f", cmap='coolwarm')
plt.title(f"Heatmap of {response_var} by {pivot_var1} and {pivot_var2}")
plt.show()

View file

@ -291,6 +291,9 @@ class WallRecommendations(BaseUtility):
self.find_insulation(u_value)
return
# If the u-value is within regulations, we don't do anything
return
raise NotImplementedError("Not implemented yet")
def _find_insulation(self, parts, u_value):

View file

@ -13,4 +13,5 @@ dbfread
pyproj
pint
geopandas
mip
mip
seaborn