Skip to content

Commit

Permalink
DOC: plot with SVG where needed
Browse files Browse the repository at this point in the history
  • Loading branch information
redeboer committed Dec 2, 2023
1 parent d5cc5d6 commit f65cd69
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 47 deletions.
11 changes: 5 additions & 6 deletions docs/amplitude-analysis.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -748,15 +748,15 @@
},
"outputs": [],
"source": [
"%config InlineBackend.figure_formats = ['svg']\n",
"import matplotlib.pyplot as plt\n",
"from matplotlib import cm\n",
"\n",
"resonances = sorted(\n",
" reaction.get_intermediate_particles(),\n",
" key=lambda p: p.mass,\n",
")\n",
"evenly_spaced_interval = np.linspace(0, 1, len(resonances))\n",
"colors = [cm.rainbow(x) for x in evenly_spaced_interval]\n",
"colors = [plt.cm.rainbow(x) for x in evenly_spaced_interval]\n",
"fig, ax = plt.subplots(figsize=(9, 4))\n",
"ax.hist(\n",
" np.real(data_frame[\"m_12\"]),\n",
Expand Down Expand Up @@ -1465,15 +1465,14 @@
"source": [
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"from matplotlib import cm\n",
"\n",
"resonances = sorted(\n",
" reaction.get_intermediate_particles(),\n",
" key=lambda p: p.mass,\n",
")\n",
"\n",
"evenly_spaced_interval = np.linspace(0, 1, len(resonances))\n",
"colors = [cm.rainbow(x) for x in evenly_spaced_interval]\n",
"colors = [plt.cm.rainbow(x) for x in evenly_spaced_interval]\n",
"\n",
"\n",
"def indicate_masses(ax):\n",
Expand Down Expand Up @@ -1917,7 +1916,7 @@
},
"outputs": [],
"source": [
"fig, ax = plt.subplots(1, figsize=(8, 5))\n",
"fig, ax = plt.subplots(figsize=(8, 5))\n",
"bins = 150\n",
"phsp_projection = np.real(phsp[\"m_12\"])\n",
"ax.hist(\n",
Expand Down Expand Up @@ -1989,7 +1988,7 @@
" sub_dataset = helicity_transformer(sub_events)\n",
" masses.append(np.real(sub_dataset[\"m_12\"]))\n",
"\n",
"fig, ax = plt.subplots(1, figsize=(8, 5))\n",
"fig, ax = plt.subplots(figsize=(8, 5))\n",
"plt.hist(masses, bins=100, stacked=True, alpha=0.6)\n",
"ax.set_xlim(0.25, 2.5)\n",
"ax.set_xlabel(R\"$m_{\\pi^0\\pi^0}$ [GeV]\")\n",
Expand Down
4 changes: 2 additions & 2 deletions docs/amplitude-analysis/analytic-continuation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,8 @@
},
"outputs": [],
"source": [
"%config InlineBackend.figure_formats = ['svg']\n",
"import numpy as np\n",
"from matplotlib import cm\n",
"\n",
"phsp = helicity_transformer(phsp_momenta)\n",
"intensities = np.array(intensity(phsp))\n",
Expand All @@ -267,7 +267,7 @@
" key=lambda p: p.mass,\n",
")\n",
"evenly_spaced_interval = np.linspace(0, 1, len(resonances))\n",
"colors = [cm.rainbow(x) for x in evenly_spaced_interval]\n",
"colors = [plt.cm.rainbow(x) for x in evenly_spaced_interval]\n",
"\n",
"fig, ax = plt.subplots()\n",
"ax.set_xlabel(\"$m_{02}$ [GeV]\")\n",
Expand Down
13 changes: 8 additions & 5 deletions docs/usage.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@
},
"outputs": [],
"source": [
"%config InlineBackend.figure_formats = ['svg']\n",
"import matplotlib.pyplot as plt\n",
"\n",
"fig, ax = plt.subplots(figsize=(5, 3))\n",
Expand Down Expand Up @@ -245,6 +246,7 @@
},
"outputs": [],
"source": [
"%config InlineBackend.figure_formats = ['svg']\n",
"%matplotlib widget\n",
"import matplotlib.pyplot as plt\n",
"from matplotlib.animation import PillowWriter\n",
Expand Down Expand Up @@ -702,19 +704,20 @@
"source_hidden": true
},
"tags": [
"full-width",
"hide-input"
]
},
"outputs": [],
"source": [
"from matplotlib import cm\n",
"%config InlineBackend.figure_formats = ['png']\n",
"\n",
"fig, (ax1, ax2) = plt.subplots(ncols=2, figsize=(7, 4.3))\n",
"fig.canvas.toolbar_visible = False\n",
"fig.canvas.header_visible = False\n",
"fig.canvas.footer_visible = False\n",
"ax1.hist2d(*cartesian_data.values(), bins=100, cmap=cm.coolwarm)\n",
"ax2.hist2d(polar_data[\"phi\"], polar_data[\"r\"], bins=100, cmap=cm.coolwarm)\n",
"ax1.hist2d(*cartesian_data.values(), bins=100, cmap=plt.cm.coolwarm)\n",
"ax2.hist2d(polar_data[\"phi\"], polar_data[\"r\"], bins=100, cmap=plt.cm.coolwarm)\n",
"fig.suptitle(\"Hit-and-miss intensity distribution\")\n",
"ax1.set_title(\"cartesian\")\n",
"ax2.set_title(\"polar\")\n",
Expand Down Expand Up @@ -770,11 +773,11 @@
},
"outputs": [],
"source": [
"%config InlineBackend.figure_formats = ['png']\n",
"%matplotlib widget\n",
"import ipywidgets\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"from matplotlib import cm\n",
"\n",
"size = 200\n",
"X, Y = np.meshgrid(\n",
Expand Down Expand Up @@ -809,7 +812,7 @@
" Z = polar_function(polar_domain)\n",
" if color_mesh is not None:\n",
" color_mesh.remove()\n",
" color_mesh = ax_interactive.pcolormesh(X, Y, Z, cmap=cm.coolwarm)"
" color_mesh = ax_interactive.pcolormesh(X, Y, Z, cmap=plt.cm.coolwarm)"
]
},
{
Expand Down
75 changes: 47 additions & 28 deletions docs/usage/basics.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@
},
"outputs": [],
"source": [
"%config InlineBackend.figure_formats = ['svg']\n",
"parameter_defaults = {\n",
" a: 0.15,\n",
" b: 0.05,\n",
Expand Down Expand Up @@ -367,9 +368,12 @@
},
"outputs": [],
"source": [
"plt.scatter(x_values, y_values)\n",
"plt.gca().set_xlabel(\"$x$\")\n",
"plt.gca().set_ylabel(\"$f(x)$\");"
"%config InlineBackend.figure_formats = ['svg']\n",
"fig, ax = plt.subplots()\n",
"ax.scatter(x_values, y_values)\n",
"ax.set_xlabel(\"$x$\")\n",
"ax.set_ylabel(\"$f(x)$\")\n",
"plt.show()"
]
},
{
Expand Down Expand Up @@ -420,50 +424,51 @@
},
"outputs": [],
"source": [
"%config InlineBackend.figure_formats = ['svg']\n",
"x_domain = np.linspace(0, 5, num=200)\n",
"y_values = function_1d({\"x\": x_domain})\n",
"fig = plt.figure(figsize=(8, 5))\n",
"plt.plot(x_domain, y_values)\n",
"plt.gca().set_xlabel(\"$x$\")\n",
"plt.gca().set_ylabel(\"$f(x)$\")\n",
"fig, ax = plt.subplots(figsize=(8, 5))\n",
"ax.plot(x_domain, y_values)\n",
"ax.set_xlabel(\"$x$\")\n",
"ax.set_ylabel(\"$f(x)$\")\n",
"\n",
"x_min = x_range[1]\n",
"x_max = x_range[2]\n",
"y_max = 0.21\n",
"x_value = 1.5\n",
"\n",
"line_segment = [[0, 0], [0, y_max]]\n",
"plt.plot(*line_segment, color=\"black\")\n",
"plt.text(\n",
"ax.plot(*line_segment, color=\"black\")\n",
"ax.text(\n",
" -0.22,\n",
" y_max / 2 * 0.5,\n",
" \"uniform sample $(0, y_{max})$\",\n",
" rotation=\"vertical\",\n",
")\n",
"plt.axhline(y=y_max, linestyle=\"dotted\", color=\"black\")\n",
"plt.text(\n",
"ax.axhline(y=y_max, linestyle=\"dotted\", color=\"black\")\n",
"ax.text(\n",
" x_min + 0.1,\n",
" y_max - 0.01,\n",
" \"$y_{max}$\",\n",
")\n",
"\n",
"line_segment = [[x_min, x_max], [0, 0]]\n",
"plt.plot(*line_segment, color=\"black\")\n",
"plt.text(\n",
"ax.plot(*line_segment, color=\"black\")\n",
"ax.text(\n",
" (x_max - x_min) / 2 - 0.22,\n",
" 0.005,\n",
" R\"uniform sample $(x_\\mathrm{min}, x_\\mathrm{max})$\",\n",
")\n",
"plt.scatter(x_value, function_1d({\"x\": x_value}))\n",
"plt.axvline(x=x_value, linestyle=\"dotted\")\n",
"ax.scatter(x_value, function_1d({\"x\": x_value}))\n",
"ax.axvline(x=x_value, linestyle=\"dotted\")\n",
"\n",
"\n",
"def draw_y_hit(x_random, y_random):\n",
"def draw_y_hit(ax, x_random, y_random):\n",
" y_value = function_1d({\"x\": x_random})\n",
" color = \"green\" if y_random < y_value else \"red\"\n",
" text = \"hit\" if y_random < y_value else \"miss\"\n",
" plt.scatter(0, y_random, color=color)\n",
" plt.arrow(\n",
" ax.scatter(0, y_random, color=color)\n",
" ax.arrow(\n",
" x=0,\n",
" y=y_random,\n",
" dx=x_random,\n",
Expand All @@ -473,11 +478,11 @@
" color=color,\n",
" linestyle=\"dotted\",\n",
" )\n",
" plt.text(x_value + 0.05, y_random, text)\n",
" ax.text(x_value + 0.05, y_random, text)\n",
"\n",
"\n",
"draw_y_hit(x_random=x_value, y_random=0.05)\n",
"draw_y_hit(x_random=x_value, y_random=0.17)"
"draw_y_hit(ax, x_random=x_value, y_random=0.05)\n",
"draw_y_hit(ax, x_random=x_value, y_random=0.17)"
]
},
{
Expand Down Expand Up @@ -564,6 +569,7 @@
},
"outputs": [],
"source": [
"%config InlineBackend.figure_formats = ['png']\n",
"plt.hist(\n",
" domain[\"x\"],\n",
" bins=200,\n",
Expand Down Expand Up @@ -636,6 +642,7 @@
},
"outputs": [],
"source": [
"%config InlineBackend.figure_formats = ['png']\n",
"plt.hist(data[\"x\"], bins=200);"
]
},
Expand Down Expand Up @@ -694,6 +701,7 @@
},
"outputs": [],
"source": [
"%config InlineBackend.figure_formats = ['png']\n",
"plt.hist(data[\"x\"], bins=200, density=True)\n",
"plt.hist(\n",
" domain[\"x\"],\n",
Expand Down Expand Up @@ -803,6 +811,7 @@
},
"outputs": [],
"source": [
"%config InlineBackend.figure_formats = ['png']\n",
"plt.hist(data[\"x\"], bins=200, density=True)\n",
"plt.hist(\n",
" domain[\"x\"],\n",
Expand Down Expand Up @@ -874,14 +883,16 @@
},
"outputs": [],
"source": [
"%config InlineBackend.figure_formats = ['svg']\n",
"fit_traceback = pd.read_csv(\"traceback-1D.csv\")\n",
"fig, (ax1, ax2) = plt.subplots(\n",
" 2, figsize=(7, 9), sharex=True, gridspec_kw={\"height_ratios\": [1, 2]}\n",
" nrows=2, figsize=(7, 9), sharex=True, gridspec_kw={\"height_ratios\": [1, 2]}\n",
")\n",
"fit_traceback.plot(\"function_call\", \"estimator_value\", ax=ax1)\n",
"fit_traceback.plot(\"function_call\", sorted(initial_parameters), ax=ax2)\n",
"fig.tight_layout()\n",
"ax2.set_xlabel(\"function call\");"
"ax2.set_xlabel(\"function call\")\n",
"plt.show()"
]
},
{
Expand Down Expand Up @@ -962,9 +973,10 @@
"metadata": {},
"outputs": [],
"source": [
"%config InlineBackend.figure_formats = ['png']\n",
"y_range = (y, -sp.pi, +sp.pi)\n",
"substituted_expr_2d = expression_2d.subs(parameter_defaults)\n",
"plot3d(substituted_expr_2d, x_range, y_range)"
"plot3d(substituted_expr_2d, x_range, y_range);"
]
},
{
Expand Down Expand Up @@ -1015,6 +1027,7 @@
},
"outputs": [],
"source": [
"%config InlineBackend.figure_formats = ['svg']\n",
"fig, axes = plt.subplots(1, 2, figsize=(8, 3))\n",
"intensities = np.array(function_2d(domain_2d))\n",
"kwargs = {\n",
Expand Down Expand Up @@ -1072,15 +1085,17 @@
},
"outputs": [],
"source": [
"fig, axes = plt.subplots(1, 2, figsize=(9, 4), sharey=True, tight_layout=True)\n",
"%config InlineBackend.figure_formats = ['png']\n",
"fig, axes = plt.subplots(ncols=2, figsize=(9, 4), sharey=True, tight_layout=True)\n",
"axes[0].hist2d(**data_2d, bins=50)\n",
"axes[1].hist2d(**domain_2d, weights=function_2d(domain_2d), bins=50)\n",
"axes[0].set_xlabel(\"$x$\")\n",
"axes[0].set_ylim([-3, +3])\n",
"axes[1].set_xlabel(\"$x$\")\n",
"axes[0].set_ylabel(\"$y$\")\n",
"axes[0].set_title(\"Data sample\")\n",
"axes[1].set_title(\"Function with optimized parameters\");"
"axes[1].set_title(\"Function with optimized parameters\")\n",
"plt.show()"
]
},
{
Expand Down Expand Up @@ -1224,6 +1239,7 @@
},
"outputs": [],
"source": [
"%config InlineBackend.figure_formats = ['png']\n",
"fig, axes = plt.subplots(1, 2, figsize=(9, 4), sharey=True, tight_layout=True)\n",
"fig.suptitle(\"Final fit result\")\n",
"axes[0].hist2d(**data_2d, bins=50)\n",
Expand All @@ -1233,7 +1249,8 @@
"axes[1].set_xlabel(\"$x$\")\n",
"axes[0].set_ylabel(\"$y$\")\n",
"axes[0].set_title(\"Data sample\")\n",
"axes[1].set_title(\"Function with optimized parameters\");"
"axes[1].set_title(\"Function with optimized parameters\")\n",
"plt.show()"
]
},
{
Expand All @@ -1257,6 +1274,7 @@
},
"outputs": [],
"source": [
"%config InlineBackend.figure_formats = ['svg']\n",
"minuit_traceback = pd.read_csv(\"traceback.csv\")\n",
"scipy_traceback = pd.read_csv(\"traceback-scipy.csv\")\n",
"fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(\n",
Expand Down Expand Up @@ -1284,7 +1302,8 @@
" loc=\"upper right\"\n",
")\n",
"fig.tight_layout()\n",
"ax2.set_xlabel(\"function call\");"
"ax2.set_xlabel(\"function call\")\n",
"plt.show()"
]
}
],
Expand Down
1 change: 1 addition & 0 deletions docs/usage/binned-fit.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
},
"outputs": [],
"source": [
"%config InlineBackend.figure_formats = ['svg']\n",
"import matplotlib.pyplot as plt\n",
"\n",
"fig, ax = plt.subplots(figsize=(8, 5))\n",
Expand Down
1 change: 1 addition & 0 deletions docs/usage/chi-squared.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@
},
"outputs": [],
"source": [
"%config InlineBackend.figure_formats = ['svg']\n",
"import matplotlib.pyplot as plt\n",
"\n",
"\n",
Expand Down
Loading

0 comments on commit f65cd69

Please sign in to comment.