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 6dcdcd1
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 17 deletions.
7 changes: 3 additions & 4 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
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
13 changes: 13 additions & 0 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,6 +368,7 @@
},
"outputs": [],
"source": [
"%config InlineBackend.figure_formats = ['svg']\n",
"plt.scatter(x_values, y_values)\n",
"plt.gca().set_xlabel(\"$x$\")\n",
"plt.gca().set_ylabel(\"$f(x)$\");"
Expand Down Expand Up @@ -420,6 +422,7 @@
},
"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",
Expand Down Expand Up @@ -564,6 +567,7 @@
},
"outputs": [],
"source": [
"%config InlineBackend.figure_formats = ['png']\n",
"plt.hist(\n",
" domain[\"x\"],\n",
" bins=200,\n",
Expand Down Expand Up @@ -636,6 +640,7 @@
},
"outputs": [],
"source": [
"%config InlineBackend.figure_formats = ['png']\n",
"plt.hist(data[\"x\"], bins=200);"
]
},
Expand Down Expand Up @@ -694,6 +699,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 +809,7 @@
},
"outputs": [],
"source": [
"%config InlineBackend.figure_formats = ['svg']\n",
"plt.hist(data[\"x\"], bins=200, density=True)\n",
"plt.hist(\n",
" domain[\"x\"],\n",
Expand Down Expand Up @@ -874,6 +881,7 @@
},
"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",
Expand Down Expand Up @@ -962,6 +970,7 @@
"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)"
Expand Down Expand Up @@ -1015,6 +1024,7 @@
},
"outputs": [],
"source": [
"%config InlineBackend.figure_formats = ['png']\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,6 +1082,7 @@
},
"outputs": [],
"source": [
"%config InlineBackend.figure_formats = ['png']\n",
"fig, axes = plt.subplots(1, 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",
Expand Down Expand Up @@ -1224,6 +1235,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 Down Expand Up @@ -1257,6 +1269,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
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
11 changes: 5 additions & 6 deletions docs/usage/unbinned-fit.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@
"%config InlineBackend.figure_formats = ['png']\n",
"import matplotlib as mpl\n",
"import matplotlib.pyplot as plt\n",
"from matplotlib import cm\n",
"\n",
"mpl.rcParams[\"figure.dpi\"] = 300\n",
"\n",
Expand All @@ -139,7 +138,7 @@
"\n",
"bins_x, bins_y = 80, 50\n",
"bin_values, bin_edges_x, bin_edges_y, _ = ax2d.hist2d(\n",
" data[\"x\"], data[\"y\"], bins=(bins_x, bins_y), cmap=cm.coolwarm\n",
" data[\"x\"], data[\"y\"], bins=(bins_x, bins_y), cmap=plt.cm.coolwarm\n",
")\n",
"xlim = 0, 4\n",
"ylim = -3, +3\n",
Expand Down Expand Up @@ -250,8 +249,8 @@
")\n",
"ax1.set_title(\"Data distribution\")\n",
"ax2.set_title(\"Initial fit model\")\n",
"ax1.hist2d(data[\"x\"], data[\"y\"], cmap=cm.coolwarm, bins=(bins_x, bins_y))\n",
"ax2.pcolormesh(X, Y, Z, cmap=cm.coolwarm)\n",
"ax1.hist2d(data[\"x\"], data[\"y\"], cmap=plt.cm.coolwarm, bins=(bins_x, bins_y))\n",
"ax2.pcolormesh(X, Y, Z, cmap=plt.cm.coolwarm)\n",
"for ax in [ax1, ax2]:\n",
" ax.set_xlim(*xlim)\n",
" ax.set_ylim(*ylim)\n",
Expand Down Expand Up @@ -330,8 +329,8 @@
")\n",
"ax1.set_title(\"Data distribution\")\n",
"ax2.set_title(\"Model with optimized parameters\")\n",
"ax1.hist2d(data[\"x\"], data[\"y\"], cmap=cm.coolwarm, bins=(bins_x, bins_y))\n",
"ax2.pcolormesh(X, Y, Z, cmap=cm.coolwarm)\n",
"ax1.hist2d(data[\"x\"], data[\"y\"], cmap=plt.cm.coolwarm, bins=(bins_x, bins_y))\n",
"ax2.pcolormesh(X, Y, Z, cmap=plt.cm.coolwarm)\n",
"for ax in [ax1, ax2]:\n",
" ax.set_xlim(*xlim)\n",
" ax.set_ylim(*ylim)\n",
Expand Down

0 comments on commit 6dcdcd1

Please sign in to comment.