From 3e098eedc60b49d8fadcadec5cd938ebc229601b Mon Sep 17 00:00:00 2001 From: jrob93 Date: Mon, 13 May 2024 22:28:21 +0100 Subject: [PATCH] update func name and add savefig --- notebooks/plotting_utilities.ipynb | 45 ++++++++++++++++++++--- src/adler/utilities/plotting_utilities.py | 11 +++++- 2 files changed, 48 insertions(+), 8 deletions(-) diff --git a/notebooks/plotting_utilities.ipynb b/notebooks/plotting_utilities.ipynb index e96b70b..3b1071c 100644 --- a/notebooks/plotting_utilities.ipynb +++ b/notebooks/plotting_utilities.ipynb @@ -29,7 +29,7 @@ "source": [ "from adler.dataclasses.AdlerPlanetoid import AdlerPlanetoid\n", "from adler.science.PhaseCurve import PhaseCurve\n", - "from adler.utilities.plotting_utilities import plot_phasecurve\n", + "from adler.utilities.plotting_utilities import plot_errorbar\n", "\n", "import numpy as np\n", "import matplotlib.pyplot as plt\n", @@ -56,7 +56,19 @@ "metadata": {}, "outputs": [], "source": [ - "fig = plot_phasecurve(planetoid, filt_list=[\"r\"])" + "fig = plot_errorbar(planetoid, filt_list=[\"r\"])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "fd41e5bf", + "metadata": {}, + "outputs": [], + "source": [ + "# we can access axes properties and update them after the fact\n", + "\n", + "# ax1.__dict__" ] }, { @@ -133,7 +145,7 @@ "outputs": [], "source": [ "# we can also pass the fig object to the plotting function again to add more data\n", - "fig2 = plot_phasecurve(planetoid, fig=fig, filt_list=[\"u\", \"g\"], label_list=[\"u\", \"g\"])\n", + "fig2 = plot_errorbar(planetoid, fig=fig, filt_list=[\"g\", \"i\"], label_list=[\"g\", \"i\"])\n", "\n", "# update the legend\n", "ax1 = fig2.axes[0]\n", @@ -153,11 +165,11 @@ { "cell_type": "code", "execution_count": null, - "id": "be921f85", + "id": "f5a183bb", "metadata": {}, "outputs": [], "source": [ - "ax1.__dict__" + "# inspect the different items that have been plotted" ] }, { @@ -187,7 +199,7 @@ "metadata": {}, "outputs": [], "source": [ - "# we can access axes properties and update them after the fact\n", + "# add the legend label to the r filter data\n", "ax1.containers[0]._label = \"r\"\n", "ax1.legend()" ] @@ -208,6 +220,27 @@ "id": "a56d5711", "metadata": {}, "outputs": [], + "source": [ + "# we can plot nothing, but save the figure\n", + "fig3 = plot_errorbar(planetoid, fig=fig2, filename=\"phase_curve_{}.png\".format(ssoid))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "1c89f107", + "metadata": {}, + "outputs": [], + "source": [ + "fig3" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b76a0b12", + "metadata": {}, + "outputs": [], "source": [] } ], diff --git a/src/adler/utilities/plotting_utilities.py b/src/adler/utilities/plotting_utilities.py index f9b1d29..a77de00 100644 --- a/src/adler/utilities/plotting_utilities.py +++ b/src/adler/utilities/plotting_utilities.py @@ -2,15 +2,16 @@ import matplotlib.gridspec as gridspec -def plot_phasecurve( +def plot_errorbar( planetoid, - filt_list=["r"], + filt_list=[], x_plot="phaseAngle", y_plot="reduced_mag", xerr_plot="magErr", fig=None, label_list=None, col_list=None, + filename=None, ): """Make an errorbar scatter plot of reduced magnitude against phase angle to show the phase curve of an Adler object. @@ -30,6 +31,8 @@ def plot_phasecurve( Optional, labels for errorbar plot elements col_list: list Optional, colors for errorbar scatter points + filename: str + Optional, if provided save the figure with this filename Returns ----------- @@ -72,4 +75,8 @@ def plot_phasecurve( # plot the errorbars ax1.errorbar(x, y, xerr, color=c, fmt="o", label=l) + # save the figure? + if filename: + fig.savefig(filename, facecolor="w", transparent=True, bbox_inches="tight") + return fig