Skip to content

Commit

Permalink
update func name and add savefig
Browse files Browse the repository at this point in the history
  • Loading branch information
jrob93 committed May 13, 2024
1 parent 424c99f commit 3e098ee
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 8 deletions.
45 changes: 39 additions & 6 deletions notebooks/plotting_utilities.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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__"
]
},
{
Expand Down Expand Up @@ -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",
Expand All @@ -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"
]
},
{
Expand Down Expand Up @@ -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()"
]
Expand All @@ -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": []
}
],
Expand Down
11 changes: 9 additions & 2 deletions src/adler/utilities/plotting_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
-----------
Expand Down Expand Up @@ -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

0 comments on commit 3e098ee

Please sign in to comment.