From 16cfa8b13f29dac4307d9c68db616dbe418c94f6 Mon Sep 17 00:00:00 2001 From: ChanceChallacombe Date: Mon, 7 Jul 2025 11:56:47 -0700 Subject: [PATCH] clean plot styling --- ..._Generation_for_Antibody_Engineering.ipynb | 9 ++---- ...sic_Scoring_for_Antibody_Engineering.ipynb | 9 ++---- ...ral_Scoring_for_Antibody_Engineering.ipynb | 9 ++---- ..._Downstream_for_Antibody_Engineering.ipynb | 7 ++--- {font => content/helpers}/Geist-Regular.ttf | Bin content/helpers/styling.py | 27 ++++++++++++++++++ 6 files changed, 38 insertions(+), 23 deletions(-) rename {font => content/helpers}/Geist-Regular.ttf (100%) create mode 100644 content/helpers/styling.py diff --git a/content/9.0_Generation_for_Antibody_Engineering.ipynb b/content/9.0_Generation_for_Antibody_Engineering.ipynb index 5a78656..aa27221 100644 --- a/content/9.0_Generation_for_Antibody_Engineering.ipynb +++ b/content/9.0_Generation_for_Antibody_Engineering.ipynb @@ -47,7 +47,7 @@ }, { "cell_type": "code", - "execution_count": 57, + "execution_count": 2, "id": "b8ed5dc9", "metadata": { "scrolled": true @@ -70,11 +70,8 @@ "from Bio.PDB import *\n", "\n", "from biolmai import BioLM\n", - "from matplotlib.font_manager import fontManager, FontProperties\n", - "font_path = \"../font/Geist-Regular.ttf\"\n", - "fontManager.addfont(font_path)\n", - "prop = FontProperties(fname=font_path)\n", - "sns.set_theme(font=prop.get_name(), style=\"white\", context='notebook', palette='pastel')" + "from helpers.styling import apply_plot_styling\n", + "apply_plot_styling()" ] }, { diff --git a/content/9.1_Intrinsic_Scoring_for_Antibody_Engineering.ipynb b/content/9.1_Intrinsic_Scoring_for_Antibody_Engineering.ipynb index c4bef6b..f7e151d 100644 --- a/content/9.1_Intrinsic_Scoring_for_Antibody_Engineering.ipynb +++ b/content/9.1_Intrinsic_Scoring_for_Antibody_Engineering.ipynb @@ -53,7 +53,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 1, "id": "b8ed5dc9", "metadata": {}, "outputs": [], @@ -73,11 +73,8 @@ "from Bio.PDB import *\n", "\n", "from biolmai import BioLM\n", - "from matplotlib.font_manager import fontManager, FontProperties\n", - "font_path = \"../font/Geist-Regular.ttf\"\n", - "fontManager.addfont(font_path)\n", - "prop = FontProperties(fname=font_path)\n", - "sns.set_theme(font=prop.get_name(), style=\"white\", context='notebook', palette='pastel')" + "from helpers.styling import apply_plot_styling\n", + "apply_plot_styling()" ] }, { diff --git a/content/9.2_Structural_Scoring_for_Antibody_Engineering.ipynb b/content/9.2_Structural_Scoring_for_Antibody_Engineering.ipynb index a25877b..17fcf02 100644 --- a/content/9.2_Structural_Scoring_for_Antibody_Engineering.ipynb +++ b/content/9.2_Structural_Scoring_for_Antibody_Engineering.ipynb @@ -46,7 +46,7 @@ }, { "cell_type": "code", - "execution_count": 36, + "execution_count": 1, "id": "b8ed5dc9", "metadata": {}, "outputs": [], @@ -66,11 +66,8 @@ "from Bio.PDB import *\n", "import os\n", "from biolmai import BioLM\n", - "from matplotlib.font_manager import fontManager, FontProperties\n", - "font_path = \"../font/Geist-Regular.ttf\"\n", - "fontManager.addfont(font_path)\n", - "prop = FontProperties(fname=font_path)\n", - "sns.set_theme(font=prop.get_name(), style=\"white\", context='notebook', palette='pastel')" + "from helpers.styling import apply_plot_styling\n", + "apply_plot_styling()" ] }, { diff --git a/content/9.3_Downstream_for_Antibody_Engineering.ipynb b/content/9.3_Downstream_for_Antibody_Engineering.ipynb index 0b0ce33..037a8cd 100644 --- a/content/9.3_Downstream_for_Antibody_Engineering.ipynb +++ b/content/9.3_Downstream_for_Antibody_Engineering.ipynb @@ -68,11 +68,8 @@ "from Bio.PDB import *\n", "\n", "from biolmai import BioLM\n", - "from matplotlib.font_manager import fontManager, FontProperties\n", - "font_path = \"../font/Geist-Regular.ttf\"\n", - "fontManager.addfont(font_path)\n", - "prop = FontProperties(fname=font_path)\n", - "sns.set_theme(font=prop.get_name(), style=\"white\", context='notebook', palette='pastel')" + "from helpers.styling import apply_plot_styling\n", + "apply_plot_styling()" ] }, { diff --git a/font/Geist-Regular.ttf b/content/helpers/Geist-Regular.ttf similarity index 100% rename from font/Geist-Regular.ttf rename to content/helpers/Geist-Regular.ttf diff --git a/content/helpers/styling.py b/content/helpers/styling.py new file mode 100644 index 0000000..27c9f43 --- /dev/null +++ b/content/helpers/styling.py @@ -0,0 +1,27 @@ +import seaborn as sns +import os +from matplotlib import rcParams +from matplotlib.font_manager import fontManager, FontProperties + +def apply_plot_styling(font_filename="Geist-Regular.ttf"): + """ + Applies custom font and Seaborn theme styling for consistent plot visuals. + + Parameters: + font_filename (str): Name of the .ttf font file located in the same directory as this script. + """ + current_dir = os.path.dirname(os.path.abspath(__file__)) + font_path = os.path.join(current_dir, font_filename) + + fontManager.addfont(font_path) + prop = FontProperties(fname=font_path) + font_name = prop.get_name() + + sns.set_theme( + font=font_name, + style="white", + context="notebook", + palette="pastel" + ) + + rcParams['font.family'] = font_name \ No newline at end of file