Skip to content

Commit

Permalink
DOC: remove titles from exported plots (#269)
Browse files Browse the repository at this point in the history
* DOC: link to watermarked figures
  • Loading branch information
redeboer authored Jan 11, 2023
1 parent 77fd841 commit 8e3bf0a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 25 deletions.
8 changes: 4 additions & 4 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@

def download_paper_figures() -> str:
files = [
"_static/images/total-polarimetry-field.svg",
"_static/images/polarimetry-field-L1520-unaligned.svg",
"_static/images/polarimetry-field-L1520-aligned.svg",
"_static/images/polarimetry-field-norm-uncertainties.png",
"_static/images/total-polarimetry-field-watermark.svg",
"_static/images/polarimetry-field-L1520-unaligned-watermark.svg",
"_static/images/polarimetry-field-L1520-aligned-watermark.svg",
"_static/images/polarimetry-field-norm-uncertainties-watermark.png",
]
for file in files:
if not os.path.exists(file):
Expand Down
53 changes: 32 additions & 21 deletions docs/uncertainties.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"source": [
"from __future__ import annotations\n",
"\n",
"import itertools\n",
"import json\n",
"import logging\n",
"import os\n",
Expand Down Expand Up @@ -1272,7 +1273,7 @@
"syst_solid_angle = jnp.nanmax(compute_solid_angle(syst_theta), axis=0)\n",
"\n",
"\n",
"def plot_angle_uncertainties(watermark: bool) -> None:\n",
"def plot_angle_uncertainties(watermark: bool, titles: bool) -> None:\n",
" plt.ioff()\n",
" fig, axes = plt.subplots(\n",
" dpi=200,\n",
Expand All @@ -1281,9 +1282,10 @@
" )\n",
" fig.subplots_adjust(wspace=0.3)\n",
" ax1, ax2 = axes\n",
" fig.suptitle(R\"Uncertainty over $\\vec\\alpha$ polar angle\", y=1.04)\n",
" ax1.set_title(R\"Statistical \\& systematic\")\n",
" ax2.set_title(\"Model\")\n",
" if titles:\n",
" fig.suptitle(R\"Uncertainty over $\\vec\\alpha$ polar angle\", y=1.04)\n",
" ax1.set_title(R\"Statistical \\& systematic\")\n",
" ax2.set_title(\"Model\")\n",
" for ax in axes:\n",
" ax.set_box_aspect(1)\n",
" ax.set_xlabel(s1_label)\n",
Expand All @@ -1310,8 +1312,10 @@
" output_file += \"-watermark\"\n",
" add_watermark_to_uncertainties(ax1)\n",
" add_watermark_to_uncertainties(ax2)\n",
" if titles:\n",
" output_file += \"-with-titles\"\n",
" fig.savefig(f\"_static/images/{output_file}.png\", bbox_inches=\"tight\")\n",
" if watermark:\n",
" if watermark and titles:\n",
" plt.show()\n",
" plt.close(fig)\n",
" plt.ion()\n",
Expand All @@ -1325,8 +1329,10 @@
"plt.rcdefaults()\n",
"use_mpl_latex_fonts()\n",
"plt.rc(\"font\", size=16)\n",
"plot_angle_uncertainties(watermark=False)\n",
"plot_angle_uncertainties(watermark=True)"
"\n",
"boolean_combinations = list(itertools.product(*2 * [[False, True]]))\n",
"for watermark, titles in tqdm(boolean_combinations, disable=NO_TQDM):\n",
" plot_angle_uncertainties(watermark, titles)"
]
},
{
Expand All @@ -1353,17 +1359,18 @@
"assert syst_alpha_rel_difference.shape == (n_models, n_events)\n",
"\n",
"\n",
"def create_figure():\n",
"def create_figure(titles: bool):\n",
" fig, axes = plt.subplots(\n",
" dpi=200,\n",
" figsize=(11.5, 4),\n",
" ncols=2,\n",
" )\n",
" fig.subplots_adjust(wspace=0.4)\n",
" ax1, ax2 = axes\n",
" fig.suptitle(R\"Uncertainty over $\\left|\\vec\\alpha\\right|$\", y=1.04)\n",
" ax1.set_title(R\"Statistical \\& systematic\")\n",
" ax2.set_title(\"Model\")\n",
" if titles:\n",
" fig.suptitle(R\"Uncertainty over $\\left|\\vec\\alpha\\right|$\", y=1.04)\n",
" ax1.set_title(R\"Statistical \\& systematic\")\n",
" ax2.set_title(\"Model\")\n",
" for ax in axes:\n",
" ax.set_box_aspect(1)\n",
" ax.set_xlabel(s1_label)\n",
Expand All @@ -1372,9 +1379,9 @@
" return fig, (ax1, ax2)\n",
"\n",
"\n",
"def plot_norm_rel_uncertainties(watermark: bool) -> None:\n",
"def plot_norm_rel_uncertainties(watermark: bool, titles: bool) -> None:\n",
" plt.ioff()\n",
" fig, (ax1, ax2) = create_figure()\n",
" fig, (ax1, ax2) = create_figure(titles)\n",
" Z = interpolate_to_grid(jnp.nanstd(stat_alpha_rel_difference, axis=0))\n",
" mesh = ax1.pcolormesh(X, Y, Z, cmap=plt.cm.YlOrRd)\n",
" mesh.set_clim(0, 100)\n",
Expand All @@ -1400,17 +1407,19 @@
" output_file += \"-watermark\"\n",
" add_watermark_to_uncertainties(ax1)\n",
" add_watermark_to_uncertainties(ax2)\n",
" if titles:\n",
" output_file += \"-with-titles\"\n",
" fig.savefig(f\"_static/images/{output_file}.png\", bbox_inches=\"tight\")\n",
" if watermark:\n",
" if watermark and titles:\n",
" plt.show()\n",
" plt.close(fig)\n",
" plt.ion()\n",
"\n",
"\n",
"def plot_norm_uncertainties(watermark: bool) -> None:\n",
"def plot_norm_uncertainties(watermark: bool, titles: bool) -> None:\n",
" plt.ioff()\n",
" vmax = 0.5\n",
" fig, (ax1, ax2) = create_figure()\n",
" fig, (ax1, ax2) = create_figure(titles)\n",
" Z = interpolate_to_grid(jnp.nanstd(stat_alpha_difference, axis=0))\n",
" mesh = ax1.pcolormesh(X, Y, Z, cmap=plt.cm.YlOrRd)\n",
" c_bar = fig.colorbar(mesh, ax=ax1, pad=0.02)\n",
Expand All @@ -1426,8 +1435,10 @@
" output_file += \"-watermark\"\n",
" add_watermark_to_uncertainties(ax1)\n",
" add_watermark_to_uncertainties(ax2)\n",
" if titles:\n",
" output_file += \"-with-titles\"\n",
" fig.savefig(f\"_static/images/{output_file}.png\", bbox_inches=\"tight\")\n",
" if watermark:\n",
" if watermark and titles:\n",
" plt.show()\n",
" plt.close(fig)\n",
" plt.ion()\n",
Expand All @@ -1437,10 +1448,10 @@
"plt.rcdefaults()\n",
"use_mpl_latex_fonts()\n",
"plt.rc(\"font\", size=18)\n",
"plot_norm_rel_uncertainties(watermark=False)\n",
"plot_norm_rel_uncertainties(watermark=True)\n",
"plot_norm_uncertainties(watermark=False)\n",
"plot_norm_uncertainties(watermark=True)"
"\n",
"for watermark, titles in tqdm(boolean_combinations, disable=NO_TQDM):\n",
" plot_norm_rel_uncertainties(watermark, titles)\n",
" plot_norm_uncertainties(watermark, titles)"
]
},
{
Expand Down

0 comments on commit 8e3bf0a

Please sign in to comment.