aboutsummaryrefslogtreecommitdiffhomepage
path: root/notebooks
diff options
context:
space:
mode:
authorAdam Janovsky2024-05-01 14:04:34 +0200
committerAdam Janovsky2024-05-01 14:04:34 +0200
commitd38b6d08d2791c2869b572a4cb32cbdd7baef940 (patch)
tree3ebc8fb4a4814479f195e95bbd42a3e646493115 /notebooks
parenta4aa019209ee379cf7b2bfbdc031fc61a99aa75c (diff)
downloadsec-certs-d38b6d08d2791c2869b572a4cb32cbdd7baef940.tar.gz
sec-certs-d38b6d08d2791c2869b572a4cb32cbdd7baef940.tar.zst
sec-certs-d38b6d08d2791c2869b572a4cb32cbdd7baef940.zip
artifacts for chain-of-trust paper
Diffstat (limited to 'notebooks')
-rw-r--r--notebooks/cc/chain_of_trust_plots.ipynb320
-rw-r--r--notebooks/cc/paper2_plots.ipynb428
2 files changed, 320 insertions, 428 deletions
diff --git a/notebooks/cc/chain_of_trust_plots.ipynb b/notebooks/cc/chain_of_trust_plots.ipynb
new file mode 100644
index 00000000..2d58af8b
--- /dev/null
+++ b/notebooks/cc/chain_of_trust_plots.ipynb
@@ -0,0 +1,320 @@
+{
+ "cells": [
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "from pathlib import Path\n",
+ "\n",
+ "import matplotlib\n",
+ "import matplotlib.dates as mdates\n",
+ "import matplotlib.pyplot as plt\n",
+ "import numpy as np\n",
+ "import pandas as pd\n",
+ "import seaborn as sns\n",
+ "from matplotlib import lines\n",
+ "from sklearn import metrics\n",
+ "\n",
+ "# LaTeX plotting\n",
+ "matplotlib.use(\"pgf\")\n",
+ "sns.set_palette(\"Set2\")\n",
+ "sns.set_context(\"paper\")\n",
+ "\n",
+ "plt.rcParams[\"pgf.texsystem\"] = \"pdflatex\"\n",
+ "plt.rcParams[\"font.family\"] = \"serif\"\n",
+ "plt.rcParams[\"text.usetex\"] = True\n",
+ "plt.rcParams[\"pgf.rcfonts\"] = False\n",
+ "\n",
+ "plt.rcParams[\"axes.linewidth\"] = 0.5\n",
+ "plt.rcParams[\"axes.labelsize\"] = 14\n",
+ "\n",
+ "plt.rcParams[\"xtick.labelsize\"] = 12\n",
+ "plt.rcParams[\"xtick.bottom\"] = True\n",
+ "plt.rcParams[\"xtick.major.size\"] = 5\n",
+ "plt.rcParams[\"xtick.major.width\"] = 0.5\n",
+ "plt.rcParams[\"xtick.major.pad\"] = 0.1\n",
+ "\n",
+ "plt.rcParams[\"ytick.labelsize\"] = 12\n",
+ "plt.rcParams[\"ytick.left\"] = True\n",
+ "plt.rcParams[\"ytick.major.size\"] = 5\n",
+ "plt.rcParams[\"ytick.major.width\"] = 0.5\n",
+ "plt.rcParams[\"ytick.major.pad\"] = 0.1\n",
+ "\n",
+ "plt.rcParams[\"legend.title_fontsize\"] = 12\n",
+ "plt.rcParams[\"legend.fontsize\"] = 12\n",
+ "plt.rcParams[\"legend.handletextpad\"] = 0.3\n",
+ "plt.rcParams[\"lines.markersize\"] = 0.5\n",
+ "plt.rcParams[\"savefig.pad_inches\"] = 0.01\n",
+ "\n",
+ "INPUT_DIR = Path(\"./paper_artifacts/chain_of_trust/data/plots/\")\n",
+ "OUTPUT_DIR = Path(\"./results/figures/\")\n",
+ "INPUT_DIR.mkdir(exist_ok=True, parents=True)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Average number of transitive references over time"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "df_to_plot = pd.read_csv(INPUT_DIR / \"avg_refs_over_time.csv\", parse_dates=[\"date\"])\n",
+ "df_to_plot[\"category\"] = df_to_plot[\"category\"].map(lambda x: \"others\" if x == \"others categories\" else x)\n",
+ "\n",
+ "plt.figure()\n",
+ "g = sns.lineplot(data=df_to_plot, x=\"date\", y=\"n_references\", hue=\"category\", errorbar=None)\n",
+ "plt.legend(frameon=True, handlelength=2, title=\"Product category\")\n",
+ "g.set_xlabel(\"\")\n",
+ "g.set_ylabel(\"Avg. \\# transitive refs.\")\n",
+ "\n",
+ "dtFmt = mdates.DateFormatter(\"%Y\")\n",
+ "g.xaxis.set_major_formatter(dtFmt)\n",
+ "g.set_xticks(\n",
+ " [\n",
+ " pd.to_datetime(\"1998-01-01\"),\n",
+ " pd.to_datetime(\"2003-01-01\"),\n",
+ " pd.to_datetime(\"2008-01-01\"),\n",
+ " pd.to_datetime(\"2013-01-01\"),\n",
+ " pd.to_datetime(\"2018-01-01\"),\n",
+ " pd.to_datetime(\"2023-01-01\"),\n",
+ " ]\n",
+ ")\n",
+ "g.figure.set_size_inches(3.9, 3)\n",
+ "plt.tight_layout(pad=0.1)\n",
+ "g.figure.savefig(OUTPUT_DIR / \"lineplot_avg_refs.pdf\")\n",
+ "g.figure.show()"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Average reach over time"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "df_to_plot = pd.read_csv(INPUT_DIR / \"avg_reach_over_time.csv\", parse_dates=[\"date\"])\n",
+ "\n",
+ "plt.figure()\n",
+ "g = sns.lineplot(data=df_to_plot, x=\"date\", y=\"n_references\", hue=\"category\", errorbar=None)\n",
+ "plt.legend(frameon=True, handlelength=2, title=\"Product category\")\n",
+ "g.set_xlabel(\"\")\n",
+ "g.set_ylabel(\"Average certificate reach\")\n",
+ "dtFmt = mdates.DateFormatter(\"%Y\")\n",
+ "g.xaxis.set_major_formatter(dtFmt)\n",
+ "g.set_xticks(\n",
+ " [\n",
+ " pd.to_datetime(\"1998-01-01\"),\n",
+ " pd.to_datetime(\"2003-01-01\"),\n",
+ " pd.to_datetime(\"2008-01-01\"),\n",
+ " pd.to_datetime(\"2013-01-01\"),\n",
+ " pd.to_datetime(\"2018-01-01\"),\n",
+ " pd.to_datetime(\"2023-01-01\"),\n",
+ " ]\n",
+ ")\n",
+ "\n",
+ "g.figure.set_size_inches(3.9, 3)\n",
+ "plt.tight_layout(pad=0.1)\n",
+ "g.figure.savefig(OUTPUT_DIR / \"lineplot_avg_reach.pdf\")\n",
+ "g.figure.show()"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Area under curve"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "plt.figure(figsize=(2.8, 1.8))\n",
+ "sns.set_palette(\"Set2\")\n",
+ "colors = plt.cm.Dark2(np.linspace(0, 1, 8))\n",
+ "\n",
+ "df_sent = pd.read_csv(INPUT_DIR / \"df_pred_sentence_transformers.csv\")\n",
+ "df_tf_idf = pd.read_csv(INPUT_DIR / \"df_pred_tf_idf.csv\")\n",
+ "df_baseline = pd.read_csv(INPUT_DIR / \"df_pred_baseline.csv\")\n",
+ "\n",
+ "fpr, tpr, thresholds = metrics.roc_curve(df_sent.y_true, df_sent.y_pred)\n",
+ "auc = metrics.roc_auc_score(df_sent.y_true, df_sent.y_pred)\n",
+ "plt.plot(fpr, tpr, label=f\"Sent. trans. (AUC={auc:.2f})\", color=colors[0])\n",
+ "\n",
+ "fpr, tpr, thresholds = metrics.roc_curve(df_tf_idf.y_true, df_tf_idf.y_pred)\n",
+ "auc = metrics.roc_auc_score(df_tf_idf.y_true, df_tf_idf.y_pred)\n",
+ "plt.plot(fpr, tpr, label=f\"TF-IDF (AUC={auc:.2f})\", color=colors[1])\n",
+ "\n",
+ "fpr, tpr, thresholds = metrics.roc_curve(df_baseline.y_true, df_baseline.y_pred)\n",
+ "auc = metrics.roc_auc_score(df_baseline.y_true, df_baseline.y_pred)\n",
+ "with plt.rc_context({\"legend.fontsize\": 8}):\n",
+ " plt.plot(fpr, tpr, label=f\"Random guess (AUC={auc:.2f})\", color=colors[2])\n",
+ "\n",
+ " plt.legend(loc=\"lower right\")\n",
+ " plt.savefig(OUTPUT_DIR / \"roc_auc.pdf\")\n",
+ " plt.show()"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Stack-bar plot of annotations in categories"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "df = pd.read_csv(INPUT_DIR / \"ref_categories_stackplot.csv\")\n",
+ "\n",
+ "ax = df.plot.barh(stacked=True, rot=0, width=0.95)\n",
+ "ax.set_ylim(-0.6, 2.6)\n",
+ "ax.set_xlabel(\"\\# references\", fontsize=12)\n",
+ "ax.set_yticklabels([\"Others\", \"Smartcard-related\", \"Smartcards\"])\n",
+ "ax.legend(title=\"Reference context\", loc=\"lower right\", frameon=True)\n",
+ "\n",
+ "plt.text(0.4, 0.8, df.iloc[2][\"Component reuse\"], transform=ax.transAxes, color=\"white\", fontsize=14)\n",
+ "plt.text(0.81, 0.8, df.iloc[2][\"Predecessor\"], transform=ax.transAxes, color=\"white\", fontsize=14)\n",
+ "\n",
+ "plt.axhline(y=1.21, xmin=0.05, xmax=0.18, color=\"black\", linewidth=0.75)\n",
+ "plt.axhline(y=0.9, xmin=0.12, xmax=0.18, color=\"black\", linewidth=0.75)\n",
+ "plt.text(0.2, 0.55, df.iloc[1][\"Component reuse\"], transform=ax.transAxes, color=\"black\", fontsize=14)\n",
+ "plt.text(0.2, 0.45, df.iloc[1][\"Predecessor\"], transform=ax.transAxes, color=\"black\", fontsize=14)\n",
+ "\n",
+ "plt.axhline(y=0.17, xmin=0.02, xmax=0.1, color=\"black\", linewidth=0.75)\n",
+ "plt.axhline(y=-0.1, xmin=0.05, xmax=0.1, color=\"black\", linewidth=0.75)\n",
+ "plt.text(0.12, 0.22, df.iloc[0][\"Component reuse\"], transform=ax.transAxes, color=\"black\", fontsize=14)\n",
+ "plt.text(0.12, 0.13, df.iloc[0][\"Predecessor\"], transform=ax.transAxes, color=\"black\", fontsize=14)\n",
+ "\n",
+ "ax.figure.set_size_inches(4, 3)\n",
+ "plt.tight_layout(pad=0.1)\n",
+ "plt.savefig(OUTPUT_DIR / \"stacked_barplot.pdf\")"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Archived certificate half-life"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "plt.figure()\n",
+ "\n",
+ "df = pd.read_csv(INPUT_DIR / \"archived_half_life.csv\")\n",
+ "\n",
+ "with plt.rc_context({\"legend.fontsize\": 10, \"legend.title_fontsize\": 10}):\n",
+ " g = sns.ecdfplot(data=df.n_days, complementary=True)\n",
+ "\n",
+ " plt.axvline(x=365, color=\"r\", linestyle=\"--\", linewidth=0.75)\n",
+ " vertical_line = lines.Line2D(\n",
+ " [], [], color=\"r\", marker=\"\", linestyle=\"--\", markersize=10, markeredgewidth=1.5, label=\"One year\"\n",
+ " )\n",
+ " plt.legend(handles=[vertical_line])\n",
+ "\n",
+ " g.figure.set_size_inches(3, 2)\n",
+ " g.set_xlim(0, 2000)\n",
+ "\n",
+ " g.set_xlabel(\"Number of days\")\n",
+ " g.set_ylabel(\"Proportion\")\n",
+ "\n",
+ " g.yaxis.set_major_formatter(matplotlib.ticker.PercentFormatter(xmax=1))\n",
+ " g.set_yticks([0, 0.25, 0.5, 0.75, 1])\n",
+ "\n",
+ " plt.tight_layout(pad=0.05)\n",
+ " g.figure.savefig(OUTPUT_DIR / \"cdf_half_life.pdf\")\n",
+ " g.figure.show()"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Age of referenced certificate in composite-evaluation products"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "plt.figure()\n",
+ "\n",
+ "df = pd.read_csv(INPUT_DIR / \"ecdf_archival_data.csv\")\n",
+ "df = df.loc[df.scheme.isin({\"FR\", \"DE\", \"NL\"})]\n",
+ "\n",
+ "with plt.rc_context({\"legend.fontsize\": 10, \"legend.title_fontsize\": 10}):\n",
+ " g = sns.ecdfplot(data=df, x=\"date_diff\", hue=\"scheme\", legend=True)\n",
+ " plt.axvline(x=540, color=\"r\", linestyle=\"--\", linewidth=0.75)\n",
+ "\n",
+ " vertical_line = lines.Line2D([], [], color=\"r\", linestyle=\"--\", markersize=10, label=\"18 months\")\n",
+ " unique_hues = df[\"scheme\"].unique()\n",
+ " handles = [\n",
+ " plt.Line2D([], [], color=g.lines[color_idx].get_color(), label=label)\n",
+ " for color_idx, label in enumerate(unique_hues)\n",
+ " ]\n",
+ "\n",
+ " handles.append(vertical_line)\n",
+ " labels = list(unique_hues) + [\"18 months\"]\n",
+ "\n",
+ " g.legend(handles=handles, labels=labels)\n",
+ "\n",
+ " g.figure.set_size_inches(3, 2)\n",
+ " g.yaxis.set_major_formatter(matplotlib.ticker.PercentFormatter(xmax=1))\n",
+ " g.set_yticks([0, 0.25, 0.5, 0.75, 1])\n",
+ " g.set_xlim(0, 2000)\n",
+ " g.set_xlabel(\"Number of days\")\n",
+ " g.set_ylabel(\"Proportion\")\n",
+ " plt.tight_layout(pad=0.05)\n",
+ " g.figure.savefig(OUTPUT_DIR / \"ref_comp_age.pdf\")\n",
+ " plt.show()"
+ ]
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "venv",
+ "language": "python",
+ "name": "python3"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 3
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython3",
+ "version": "3.11.5"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 2
+}
diff --git a/notebooks/cc/paper2_plots.ipynb b/notebooks/cc/paper2_plots.ipynb
deleted file mode 100644
index b866e1dc..00000000
--- a/notebooks/cc/paper2_plots.ipynb
+++ /dev/null
@@ -1,428 +0,0 @@
-{
- "cells": [
- {
- "cell_type": "code",
- "execution_count": 5,
- "metadata": {},
- "outputs": [
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "/var/folders/1h/qt5h035n5rzcjdmfl295hrk80000gn/T/ipykernel_32080/1071189253.py:20: MatplotlibDeprecationWarning: Auto-close()ing of figures upon backend switching is deprecated since 3.8 and will be removed two minor releases later. To suppress this warning, explicitly call plt.close('all') first.\n",
- " matplotlib.use(\"pgf\")\n"
- ]
- }
- ],
- "source": [
- "import warnings\n",
- "from pathlib import Path\n",
- "\n",
- "import matplotlib\n",
- "import matplotlib.dates as mdates\n",
- "import matplotlib.pyplot as plt\n",
- "import numpy as np\n",
- "import pandas as pd\n",
- "import seaborn as sns\n",
- "from matplotlib import lines\n",
- "from notebooks.fixed_sankey_plot import sankey\n",
- "from sklearn import metrics\n",
- "\n",
- "# Surpress user warnings\n",
- "warnings.filterwarnings(\"ignore\", category=UserWarning)\n",
- "\n",
- "%matplotlib inline\n",
- "\n",
- "# LaTeX plotting\n",
- "matplotlib.use(\"pgf\")\n",
- "plt.rcParams[\"pgf.texsystem\"] = \"pdflatex\"\n",
- "plt.rcParams[\"font.family\"] = \"serif\"\n",
- "plt.rcParams[\"text.usetex\"] = True\n",
- "plt.rcParams[\"pgf.rcfonts\"] = False\n",
- "\n",
- "plt.rcParams[\"axes.linewidth\"] = 0.5\n",
- "plt.rcParams[\"legend.fontsize\"] = 6.5\n",
- "plt.rcParams[\"xtick.labelsize\"] = 8\n",
- "plt.rcParams[\"ytick.labelsize\"] = 8\n",
- "plt.rcParams[\"ytick.left\"] = True\n",
- "plt.rcParams[\"ytick.major.size\"] = 5\n",
- "plt.rcParams[\"ytick.major.width\"] = 0.5\n",
- "plt.rcParams[\"ytick.major.pad\"] = 0\n",
- "plt.rcParams[\"xtick.bottom\"] = True\n",
- "plt.rcParams[\"xtick.major.size\"] = 5\n",
- "plt.rcParams[\"xtick.major.width\"] = 0.5\n",
- "plt.rcParams[\"xtick.major.pad\"] = 0\n",
- "\n",
- "plt.rcParams[\"axes.titlesize\"] = 8\n",
- "plt.rcParams[\"legend.handletextpad\"] = 0.3\n",
- "plt.rcParams[\"lines.markersize\"] = 0.5\n",
- "plt.rcParams[\"savefig.pad_inches\"] = 0.01\n",
- "\n",
- "# plt.style.use(\"default\")\n",
- "# sns.set_theme(style=\"white\")\n",
- "sns.set_palette(\"Set2\")\n",
- "sns.set_context(\"paper\") # Set to \"paper\" for use in paper :)\n",
- "\n",
- "# plt.rcParams['figure.figsize'] = (10, 6)\n",
- "\n",
- "REPO_ROOT = Path().resolve()\n",
- "RESULTS_DIR = Path(\"./results/references\")\n",
- "RESULTS_DIR.mkdir(exist_ok=True, parents=True)\n",
- "\n",
- "DATASET_PATH = REPO_ROOT / \"dataset/cc_november_23/dataset.json\"\n",
- "PREDICTIONS_PATH = REPO_ROOT / \"dataset/reference_prediction/predictions.csv\"\n",
- "\n",
- "SMARTCARD_CATEGORY = \"ICs, Smart Cards and Smart Card-Related Devices and Systems\"\n",
- "CARD_RELATED_CAT = {\"Other Devices and Systems\", \"Products for Digital Signatures\", \"Trusted Computing\"}\n",
- "OTHERS_CAR = {\n",
- " \"Access Control Devices and Systems\",\n",
- " \"Biometric Systems and Devices\",\n",
- " \"Boundary Protection Devices and Systems\",\n",
- " \"Data Protection\",\n",
- " \"Databases\",\n",
- " \"Detection Devices and Systems\",\n",
- " \"Key Management Systems\",\n",
- " \"Mobility\",\n",
- " \"Multi-Function Devices\",\n",
- " \"Network and Network-Related Devices and Systems\",\n",
- " \"Operating Systems\",\n",
- "}"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "## Top-reach certificates in time"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 6,
- "metadata": {},
- "outputs": [],
- "source": [
- "plt.rcParams[\"legend.fontsize\"] = 9\n",
- "plt.rcParams[\"xtick.labelsize\"] = 12\n",
- "plt.rcParams[\"ytick.labelsize\"] = 12\n",
- "\n",
- "df_to_plot = pd.read_csv(RESULTS_DIR / \"average_reach_over_time.csv\", parse_dates=[\"date\"])\n",
- "\n",
- "plt.figure()\n",
- "g = sns.lineplot(data=df_to_plot, x=\"date\", y=\"reach\", hue=\"certificate\", errorbar=None)\n",
- "\n",
- "plt.legend(frameon=False, handlelength=2)\n",
- "g.set_xlabel(\"\")\n",
- "g.set_ylabel(\"Certificate reach\", fontsize=12)\n",
- "\n",
- "\n",
- "dtFmt = mdates.DateFormatter(\"%Y\") # define the formatting\n",
- "g.xaxis.set_major_formatter(dtFmt)\n",
- "g.set_xticks(\n",
- " [\n",
- " pd.to_datetime(\"1998-01-01\"),\n",
- " pd.to_datetime(\"2003-01-01\"),\n",
- " pd.to_datetime(\"2008-01-01\"),\n",
- " pd.to_datetime(\"2013-01-01\"),\n",
- " pd.to_datetime(\"2018-01-01\"),\n",
- " pd.to_datetime(\"2023-01-01\"),\n",
- " ]\n",
- ")\n",
- "g.figure.set_size_inches(3.9, 3)\n",
- "plt.tight_layout(pad=0.1)\n",
- "g.figure.savefig(RESULTS_DIR / \"lineplot_top_reach.pdf\")\n",
- "g.figure.savefig(RESULTS_DIR / \"lineplot_top_reach.pgf\")\n",
- "g.figure.show()"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "## Average number of transitive references over time"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 3,
- "metadata": {},
- "outputs": [
- {
- "ename": "FileNotFoundError",
- "evalue": "[Errno 2] No such file or directory: 'results/references/avg_refs_over_time.csv'",
- "output_type": "error",
- "traceback": [
- "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
- "\u001b[0;31mFileNotFoundError\u001b[0m Traceback (most recent call last)",
- "Cell \u001b[0;32mIn[3], line 5\u001b[0m\n\u001b[1;32m 3\u001b[0m plt\u001b[38;5;241m.\u001b[39mrcParams[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mytick.labelsize\u001b[39m\u001b[38;5;124m\"\u001b[39m] \u001b[38;5;241m=\u001b[39m \u001b[38;5;241m12\u001b[39m\n\u001b[1;32m 4\u001b[0m sns\u001b[38;5;241m.\u001b[39mset_palette(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mSet2\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m----> 5\u001b[0m df_to_plot \u001b[38;5;241m=\u001b[39m \u001b[43mpd\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mread_csv\u001b[49m\u001b[43m(\u001b[49m\u001b[43mRESULTS_DIR\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m/\u001b[39;49m\u001b[43m \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mavg_refs_over_time.csv\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mparse_dates\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mdate\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 6\u001b[0m df_to_plot[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mcategory\u001b[39m\u001b[38;5;124m\"\u001b[39m] \u001b[38;5;241m=\u001b[39m df_to_plot[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mcategory\u001b[39m\u001b[38;5;124m\"\u001b[39m]\u001b[38;5;241m.\u001b[39mmap(\u001b[38;5;28;01mlambda\u001b[39;00m x: \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mothers\u001b[39m\u001b[38;5;124m\"\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m x \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mothers categories\u001b[39m\u001b[38;5;124m\"\u001b[39m \u001b[38;5;28;01melse\u001b[39;00m x)\n\u001b[1;32m 7\u001b[0m plt\u001b[38;5;241m.\u001b[39mfigure()\n",
- "File \u001b[0;32m~/phd/projects/certificates/sec-certs/venv/lib/python3.11/site-packages/pandas/io/parsers/readers.py:948\u001b[0m, in \u001b[0;36mread_csv\u001b[0;34m(filepath_or_buffer, sep, delimiter, header, names, index_col, usecols, dtype, engine, converters, true_values, false_values, skipinitialspace, skiprows, skipfooter, nrows, na_values, keep_default_na, na_filter, verbose, skip_blank_lines, parse_dates, infer_datetime_format, keep_date_col, date_parser, date_format, dayfirst, cache_dates, iterator, chunksize, compression, thousands, decimal, lineterminator, quotechar, quoting, doublequote, escapechar, comment, encoding, encoding_errors, dialect, on_bad_lines, delim_whitespace, low_memory, memory_map, float_precision, storage_options, dtype_backend)\u001b[0m\n\u001b[1;32m 935\u001b[0m kwds_defaults \u001b[38;5;241m=\u001b[39m _refine_defaults_read(\n\u001b[1;32m 936\u001b[0m dialect,\n\u001b[1;32m 937\u001b[0m delimiter,\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 944\u001b[0m dtype_backend\u001b[38;5;241m=\u001b[39mdtype_backend,\n\u001b[1;32m 945\u001b[0m )\n\u001b[1;32m 946\u001b[0m kwds\u001b[38;5;241m.\u001b[39mupdate(kwds_defaults)\n\u001b[0;32m--> 948\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43m_read\u001b[49m\u001b[43m(\u001b[49m\u001b[43mfilepath_or_buffer\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mkwds\u001b[49m\u001b[43m)\u001b[49m\n",
- "File \u001b[0;32m~/phd/projects/certificates/sec-certs/venv/lib/python3.11/site-packages/pandas/io/parsers/readers.py:611\u001b[0m, in \u001b[0;36m_read\u001b[0;34m(filepath_or_buffer, kwds)\u001b[0m\n\u001b[1;32m 608\u001b[0m _validate_names(kwds\u001b[38;5;241m.\u001b[39mget(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mnames\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;28;01mNone\u001b[39;00m))\n\u001b[1;32m 610\u001b[0m \u001b[38;5;66;03m# Create the parser.\u001b[39;00m\n\u001b[0;32m--> 611\u001b[0m parser \u001b[38;5;241m=\u001b[39m \u001b[43mTextFileReader\u001b[49m\u001b[43m(\u001b[49m\u001b[43mfilepath_or_buffer\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwds\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 613\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m chunksize \u001b[38;5;129;01mor\u001b[39;00m iterator:\n\u001b[1;32m 614\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m parser\n",
- "File \u001b[0;32m~/phd/projects/certificates/sec-certs/venv/lib/python3.11/site-packages/pandas/io/parsers/readers.py:1448\u001b[0m, in \u001b[0;36mTextFileReader.__init__\u001b[0;34m(self, f, engine, **kwds)\u001b[0m\n\u001b[1;32m 1445\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39moptions[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mhas_index_names\u001b[39m\u001b[38;5;124m\"\u001b[39m] \u001b[38;5;241m=\u001b[39m kwds[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mhas_index_names\u001b[39m\u001b[38;5;124m\"\u001b[39m]\n\u001b[1;32m 1447\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mhandles: IOHandles \u001b[38;5;241m|\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m\n\u001b[0;32m-> 1448\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_engine \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_make_engine\u001b[49m\u001b[43m(\u001b[49m\u001b[43mf\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mengine\u001b[49m\u001b[43m)\u001b[49m\n",
- "File \u001b[0;32m~/phd/projects/certificates/sec-certs/venv/lib/python3.11/site-packages/pandas/io/parsers/readers.py:1705\u001b[0m, in \u001b[0;36mTextFileReader._make_engine\u001b[0;34m(self, f, engine)\u001b[0m\n\u001b[1;32m 1703\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mb\u001b[39m\u001b[38;5;124m\"\u001b[39m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;129;01min\u001b[39;00m mode:\n\u001b[1;32m 1704\u001b[0m mode \u001b[38;5;241m+\u001b[39m\u001b[38;5;241m=\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mb\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m-> 1705\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mhandles \u001b[38;5;241m=\u001b[39m \u001b[43mget_handle\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 1706\u001b[0m \u001b[43m \u001b[49m\u001b[43mf\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1707\u001b[0m \u001b[43m \u001b[49m\u001b[43mmode\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1708\u001b[0m \u001b[43m \u001b[49m\u001b[43mencoding\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43moptions\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mget\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mencoding\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mNone\u001b[39;49;00m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1709\u001b[0m \u001b[43m \u001b[49m\u001b[43mcompression\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43moptions\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mget\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mcompression\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mNone\u001b[39;49;00m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1710\u001b[0m \u001b[43m \u001b[49m\u001b[43mmemory_map\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43moptions\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mget\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mmemory_map\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mFalse\u001b[39;49;00m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1711\u001b[0m \u001b[43m \u001b[49m\u001b[43mis_text\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mis_text\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1712\u001b[0m \u001b[43m \u001b[49m\u001b[43merrors\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43moptions\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mget\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mencoding_errors\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mstrict\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1713\u001b[0m \u001b[43m \u001b[49m\u001b[43mstorage_options\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43moptions\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mget\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mstorage_options\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mNone\u001b[39;49;00m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 1714\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 1715\u001b[0m \u001b[38;5;28;01massert\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mhandles \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m\n\u001b[1;32m 1716\u001b[0m f \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mhandles\u001b[38;5;241m.\u001b[39mhandle\n",
- "File \u001b[0;32m~/phd/projects/certificates/sec-certs/venv/lib/python3.11/site-packages/pandas/io/common.py:863\u001b[0m, in \u001b[0;36mget_handle\u001b[0;34m(path_or_buf, mode, encoding, compression, memory_map, is_text, errors, storage_options)\u001b[0m\n\u001b[1;32m 858\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(handle, \u001b[38;5;28mstr\u001b[39m):\n\u001b[1;32m 859\u001b[0m \u001b[38;5;66;03m# Check whether the filename is to be opened in binary mode.\u001b[39;00m\n\u001b[1;32m 860\u001b[0m \u001b[38;5;66;03m# Binary mode does not support 'encoding' and 'newline'.\u001b[39;00m\n\u001b[1;32m 861\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m ioargs\u001b[38;5;241m.\u001b[39mencoding \u001b[38;5;129;01mand\u001b[39;00m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mb\u001b[39m\u001b[38;5;124m\"\u001b[39m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;129;01min\u001b[39;00m ioargs\u001b[38;5;241m.\u001b[39mmode:\n\u001b[1;32m 862\u001b[0m \u001b[38;5;66;03m# Encoding\u001b[39;00m\n\u001b[0;32m--> 863\u001b[0m handle \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mopen\u001b[39;49m\u001b[43m(\u001b[49m\n\u001b[1;32m 864\u001b[0m \u001b[43m \u001b[49m\u001b[43mhandle\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 865\u001b[0m \u001b[43m \u001b[49m\u001b[43mioargs\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mmode\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 866\u001b[0m \u001b[43m \u001b[49m\u001b[43mencoding\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mioargs\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mencoding\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 867\u001b[0m \u001b[43m \u001b[49m\u001b[43merrors\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43merrors\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 868\u001b[0m \u001b[43m \u001b[49m\u001b[43mnewline\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[1;32m 869\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 870\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m 871\u001b[0m \u001b[38;5;66;03m# Binary mode\u001b[39;00m\n\u001b[1;32m 872\u001b[0m handle \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mopen\u001b[39m(handle, ioargs\u001b[38;5;241m.\u001b[39mmode)\n",
- "\u001b[0;31mFileNotFoundError\u001b[0m: [Errno 2] No such file or directory: 'results/references/avg_refs_over_time.csv'"
- ]
- }
- ],
- "source": [
- "plt.rcParams[\"legend.fontsize\"] = 9\n",
- "plt.rcParams[\"xtick.labelsize\"] = 12\n",
- "plt.rcParams[\"ytick.labelsize\"] = 12\n",
- "sns.set_palette(\"Set2\")\n",
- "df_to_plot = pd.read_csv(RESULTS_DIR / \"avg_refs_over_time.csv\", parse_dates=[\"date\"])\n",
- "df_to_plot[\"category\"] = df_to_plot[\"category\"].map(lambda x: \"others\" if x == \"others categories\" else x)\n",
- "plt.figure()\n",
- "g = sns.lineplot(data=df_to_plot, x=\"date\", y=\"n_references\", hue=\"category\", errorbar=None)\n",
- "\n",
- "plt.legend(frameon=True, handlelength=2, title=\"Product category\")\n",
- "g.set_xlabel(\"\")\n",
- "g.set_ylabel(\"Avg. # transitive refs.\", fontsize=12)\n",
- "\n",
- "dtFmt = mdates.DateFormatter(\"%Y\") # define the formatting\n",
- "g.xaxis.set_major_formatter(dtFmt)\n",
- "g.set_xticks(\n",
- " [\n",
- " pd.to_datetime(\"1998-01-01\"),\n",
- " pd.to_datetime(\"2003-01-01\"),\n",
- " pd.to_datetime(\"2008-01-01\"),\n",
- " pd.to_datetime(\"2013-01-01\"),\n",
- " pd.to_datetime(\"2018-01-01\"),\n",
- " pd.to_datetime(\"2023-01-01\"),\n",
- " ]\n",
- ")\n",
- "g.figure.set_size_inches(3.9, 3)\n",
- "plt.tight_layout(pad=0.1)\n",
- "g.figure.savefig(\n",
- " RESULTS_DIR / \"lineplot_avg_refs.pdf\",\n",
- ")\n",
- "g.figure.show()"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "## Average reach over time"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
- "source": [
- "plt.rcParams[\"legend.fontsize\"] = 9\n",
- "plt.rcParams[\"xtick.labelsize\"] = 12\n",
- "plt.rcParams[\"ytick.labelsize\"] = 12\n",
- "sns.set_palette(\"Set2\")\n",
- "df_to_plot = pd.read_csv(RESULTS_DIR / \"avg_reach_over_time.csv\", parse_dates=[\"date\"])\n",
- "plt.figure()\n",
- "g = sns.lineplot(data=df_to_plot, x=\"date\", y=\"n_references\", hue=\"category\", errorbar=None)\n",
- "\n",
- "plt.legend(frameon=True, handlelength=2, title=\"Product category\")\n",
- "g.set_xlabel(\"\")\n",
- "g.set_ylabel(\"Average certificate reach\", fontsize=12)\n",
- "\n",
- "dtFmt = mdates.DateFormatter(\"%Y\") # define the formatting\n",
- "g.xaxis.set_major_formatter(dtFmt)\n",
- "g.set_xticks(\n",
- " [\n",
- " pd.to_datetime(\"1998-01-01\"),\n",
- " pd.to_datetime(\"2003-01-01\"),\n",
- " pd.to_datetime(\"2008-01-01\"),\n",
- " pd.to_datetime(\"2013-01-01\"),\n",
- " pd.to_datetime(\"2018-01-01\"),\n",
- " pd.to_datetime(\"2023-01-01\"),\n",
- " ]\n",
- ")\n",
- "g.figure.set_size_inches(3.9, 3)\n",
- "plt.tight_layout(pad=0.1)\n",
- "g.figure.savefig(RESULTS_DIR / \"lineplot_avg_reach.pdf\")\n",
- "g.figure.show()"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "## Area under curve"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
- "source": [
- "plt.figure(figsize=(2.8, 1.8))\n",
- "sns.set_palette(\"Set2\")\n",
- "colors = plt.cm.Dark2(np.linspace(0, 1, 8))\n",
- "\n",
- "df_sent = pd.read_csv(RESULTS_DIR / \"df_pred_sentence_transformers.csv\")\n",
- "df_tf_idf = pd.read_csv(RESULTS_DIR / \"df_pred_tf_idf.csv\")\n",
- "df_baseline = pd.read_csv(RESULTS_DIR / \"df_pred_baseline.csv\")\n",
- "\n",
- "fpr, tpr, thresholds = metrics.roc_curve(df_sent.y_true, df_sent.y_pred)\n",
- "auc = metrics.roc_auc_score(df_sent.y_true, df_sent.y_pred)\n",
- "plt.plot(fpr, tpr, label=f\"Sent. trans. (AUC={auc:.2f})\", color=colors[0])\n",
- "\n",
- "fpr, tpr, thresholds = metrics.roc_curve(df_tf_idf.y_true, df_tf_idf.y_pred)\n",
- "auc = metrics.roc_auc_score(df_tf_idf.y_true, df_tf_idf.y_pred)\n",
- "plt.plot(fpr, tpr, label=f\"TF-IDF (AUC={auc:.2f})\", color=colors[1])\n",
- "\n",
- "fpr, tpr, thresholds = metrics.roc_curve(df_baseline.y_true, df_baseline.y_pred)\n",
- "auc = metrics.roc_auc_score(df_baseline.y_true, df_baseline.y_pred)\n",
- "plt.plot(fpr, tpr, label=f\"Random guess (AUC={auc:.2f})\", color=colors[2])\n",
- "\n",
- "plt.legend(loc=\"lower right\")\n",
- "plt.tight_layout(pad=0.1)\n",
- "plt.savefig(RESULTS_DIR / \"roc_auc.pdf\")\n",
- "plt.show()"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "## Stack-bar plot of annotations in categories"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
- "source": [
- "df = pd.read_csv(RESULTS_DIR / \"ref_categories_stackplot.csv\")\n",
- "\n",
- "ax = df.plot.barh(stacked=True, rot=0, width=0.95)\n",
- "ax.set_ylim(-0.6, 2.6)\n",
- "ax.set_xlabel(\"# references\", fontsize=10)\n",
- "ax.set_yticklabels([\"Others\", \"Smartcard-related\", \"Smartcards\"], fontsize=10)\n",
- "ax.legend(title=\"Reference context\", loc=\"lower right\", frameon=True)\n",
- "\n",
- "plt.text(0.4, 0.8, df.iloc[2][\"Component reuse\"], transform=ax.transAxes, color=\"white\", fontsize=10)\n",
- "plt.text(0.83, 0.8, df.iloc[2][\"Predecessor\"], transform=ax.transAxes, color=\"white\", fontsize=10)\n",
- "\n",
- "plt.axhline(y=1.21, xmin=0.05, xmax=0.18, color=\"black\", linewidth=0.75)\n",
- "plt.axhline(y=0.9, xmin=0.12, xmax=0.18, color=\"black\", linewidth=0.75)\n",
- "plt.text(0.2, 0.55, df.iloc[1][\"Component reuse\"], transform=ax.transAxes, color=\"black\", fontsize=10)\n",
- "plt.text(0.2, 0.45, df.iloc[1][\"Predecessor\"], transform=ax.transAxes, color=\"black\", fontsize=10)\n",
- "\n",
- "plt.axhline(y=0.17, xmin=0.02, xmax=0.1, color=\"black\", linewidth=0.75)\n",
- "plt.axhline(y=-0.1, xmin=0.05, xmax=0.1, color=\"black\", linewidth=0.75)\n",
- "plt.text(0.12, 0.22, df.iloc[0][\"Component reuse\"], transform=ax.transAxes, color=\"black\", fontsize=10)\n",
- "plt.text(0.12, 0.13, df.iloc[0][\"Predecessor\"], transform=ax.transAxes, color=\"black\", fontsize=10)\n",
- "\n",
- "ax.figure.set_size_inches(4, 3)\n",
- "plt.tight_layout(pad=0.1)\n",
- "plt.savefig(RESULTS_DIR / \"stacked_barplot.pdf\")"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "## Archived certificate half-life"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
- "source": [
- "plt.figure()\n",
- "\n",
- "df = pd.read_csv(RESULTS_DIR / \"archived_half_life.csv\")\n",
- "g = sns.ecdfplot(data=df.n_days, complementary=True)\n",
- "\n",
- "plt.axvline(x=365, color=\"r\", linestyle=\"--\", linewidth=0.75)\n",
- "vertical_line = lines.Line2D(\n",
- " [], [], color=\"r\", marker=\"\", linestyle=\"--\", markersize=10, markeredgewidth=1.5, label=\"One year\"\n",
- ")\n",
- "plt.legend(handles=[vertical_line])\n",
- "\n",
- "g.figure.set_size_inches(3, 2)\n",
- "g.set_xlim(0, 2000)\n",
- "\n",
- "g.set_xlabel(\"Number of days\")\n",
- "g.set_ylabel(\"Proportion\")\n",
- "\n",
- "g.yaxis.set_major_formatter(matplotlib.ticker.PercentFormatter(xmax=1))\n",
- "g.set_yticks([0, 0.25, 0.5, 0.75, 1])\n",
- "\n",
- "plt.tight_layout(pad=0.05)\n",
- "g.figure.savefig(RESULTS_DIR / \"cdf_half_life.pdf\")\n",
- "g.figure.show()"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "## Age of referenced certificate in composite-evaluation products"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
- "source": [
- "plt.figure()\n",
- "\n",
- "df = pd.read_csv(RESULTS_DIR / \"ecdf_archival_data.csv\")\n",
- "df = df.loc[df.scheme.isin({\"FR\", \"DE\", \"NL\"})]\n",
- "\n",
- "g = sns.ecdfplot(data=df, x=\"date_diff\", hue=\"scheme\", legend=True)\n",
- "plt.axvline(x=540, color=\"r\", linestyle=\"--\", linewidth=0.75)\n",
- "\n",
- "vertical_line = lines.Line2D([], [], color=\"r\", linestyle=\"--\", markersize=10, label=\"18 months\")\n",
- "unique_hues = df[\"scheme\"].unique()\n",
- "handles = [\n",
- " plt.Line2D([], [], color=g.lines[color_idx].get_color(), label=label) for color_idx, label in enumerate(unique_hues)\n",
- "]\n",
- "\n",
- "handles.append(vertical_line)\n",
- "labels = list(unique_hues) + [\"18 months\"]\n",
- "\n",
- "g.legend(handles=handles, labels=labels)\n",
- "\n",
- "# Your code to finalize and save the plot\n",
- "g.figure.set_size_inches(3, 2)\n",
- "\n",
- "# plt.tight_layout(pad=1.17)\n",
- "g.yaxis.set_major_formatter(matplotlib.ticker.PercentFormatter(xmax=1))\n",
- "g.set_yticks([0, 0.25, 0.5, 0.75, 1])\n",
- "g.set_xlim(0, 2000)\n",
- "g.set_xlabel(\"Number of days\")\n",
- "g.set_ylabel(\"Proportion\")\n",
- "plt.tight_layout(pad=0.05)\n",
- "g.figure.savefig(RESULTS_DIR / \"ref_comp_age.pdf\")\n",
- "plt.show()"
- ]
- }
- ],
- "metadata": {
- "kernelspec": {
- "display_name": "venv",
- "language": "python",
- "name": "python3"
- },
- "language_info": {
- "codemirror_mode": {
- "name": "ipython",
- "version": 3
- },
- "file_extension": ".py",
- "mimetype": "text/x-python",
- "name": "python",
- "nbconvert_exporter": "python",
- "pygments_lexer": "ipython3",
- "version": "3.11.5"
- }
- },
- "nbformat": 4,
- "nbformat_minor": 2
-}