Skip to content

Commit

Permalink
add figure options and colors
Browse files Browse the repository at this point in the history
  • Loading branch information
gituser789 committed Oct 5, 2024
1 parent f70a724 commit 91b568f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
28 changes: 28 additions & 0 deletions hct/generalplotsettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,31 @@ def global_plot_settings_font_sansserif() -> None:
"text.usetex": True,
"font.family": "sans-serif",
"font.sans-serif": ["Helvetica"]})

def global_plot_settings_font_size(font_size: float) -> None:
"""
Change the plot font size.
:param font_size: font size
:type font_size: float
"""
font = {'size': font_size}
plt.rc('font', **font)


def colors() -> dict:
"""Colors according to the GNOME color scheme (Color 4)."""
nominator = 255
color_dict = {
"blue": tuple(ti / nominator for ti in (28, 113, 216)),
'red': tuple(ti / nominator for ti in (192, 28, 40)),
"green": tuple(ti / nominator for ti in (46, 194, 126)),
"orange": tuple(ti / nominator for ti in (230, 97, 0)),
"purple": tuple(ti / nominator for ti in (129, 61, 156)),
"brown": tuple(ti / nominator for ti in (134, 94, 60)),
"grey": tuple(ti / nominator for ti in (119, 118, 123)),
"yellow": tuple(ti / nominator for ti in (245, 194, 17)),
"black": tuple(ti / nominator for ti in (0, 0, 0)),
"white": tuple(ti / nominator for ti in (255, 255, 255))
}
return color_dict
15 changes: 11 additions & 4 deletions hct/hydrodynamic.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,15 +234,20 @@ def read_fan_data(filepath: str):
return fan_cubic_meter_second, fan_pressure_drop_pascal


def calc_volume_flow(fan_name: str, geometry: Geometry, plot: bool = False):
def calc_volume_flow(fan_name: str, geometry: Geometry, plot: bool = False, figure_size: tuple | None = None):
"""
Calculate the volume flow for a given fan and a given geometry.
This function calculates the intersection of both graphs, the fan graph and the heatsink pressure graph and returns the intersection point.
:param fan_name: file name including .csv ending
:type fan_name: str
:param geometry: Geometry.
:type geometry: Geometry
:param plot: True to show a visual output.
:type plot: bool
:param figure_size: Figure size in mm, e.g. (80, 60) is a 80 mm wide and 60 mm height plot
:type figure_size: tuple
:return: intersection_volume_flow, intersection_pressure
"""
fan_directory = os.path.join(os.path.dirname(__file__), "data", fan_name)
Expand Down Expand Up @@ -295,13 +300,15 @@ def calc_volume_flow(fan_name: str, geometry: Geometry, plot: bool = False):
fan_cubic_meter_second, result_list_delta_p_total, fan_pressure_drop_pascal)

if plot:
plt.plot(fan_cubic_meter_second, np.array(result_list_delta_p_total), label=r'Heat sink')
plt.plot(fan_cubic_meter_second, fan_pressure_drop_pascal, label=f"Fan: {fan_name.replace('.csv', '')}")
plt.plot(intersection_volume_flow, intersection_pressure, 'ro')
plt.figure(figsize=[x / 25.4 for x in figure_size] if figure_size is not None else None, dpi=80)
plt.plot(fan_cubic_meter_second, np.array(result_list_delta_p_total), label=r'Heat sink', color=colors()["blue"])
plt.plot(fan_cubic_meter_second, fan_pressure_drop_pascal, label="Fan", color=colors()["orange"]) # : {fan_name.replace('.csv', '')}
plt.plot(intersection_volume_flow, intersection_pressure, color=colors()["red"], marker='o')
plt.xlabel('Volume flow im m³/s')
plt.ylabel(r'Pressure drop $\Delta p$ in Pa')
plt.grid()
plt.legend()
plt.tight_layout()
plt.show()

return intersection_volume_flow, intersection_pressure
Expand Down

0 comments on commit 91b568f

Please sign in to comment.