Skip to content

Commit

Permalink
Added aastex.Figure() class.
Browse files Browse the repository at this point in the history
  • Loading branch information
byrdie committed Oct 28, 2023
1 parent d01ca8d commit 70ccd71
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
13 changes: 12 additions & 1 deletion aastex/_aastex.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import dataclasses
import pathlib
import pylatex
from pylatex import Package
from pylatex import (
NoEscape,
Package,
Figure,
)

__all__ = [
"text_width_inches",
"column_width_inches",
"Title",
"Affiliation",
"Author",
Expand All @@ -12,9 +18,14 @@
"Abstract",
"Section",
"Document",
"NoEscape",
"Package",
"Figure",
]

text_width_inches = 513.11743 / 72
column_width_inches = 242.26653 / 72


@dataclasses.dataclass
class Title(pylatex.base_classes.LatexObject):
Expand Down
16 changes: 16 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ Here is a simple example showing some of the basic features of :mod:`aastex`.
.. jupyter-execute::

import pathlib
import numpy as np
import matplotlib.pyplot as plt
import aastex

title = aastex.Title("An Interesting Article")
Expand All @@ -49,11 +51,25 @@ Here is a simple example showing some of the basic features of :mod:`aastex`.
intro.packages.append(aastex.Package("lipsum"))
intro.append(r"\lipsum[2-4]")

fig, ax = plt.subplots(figsize=(aastex.column_width_inches, 2))
data = np.random.normal(size=(11, 11))
ax.plot(data)
path_data = pathlib.Path("data.pdf")
fig.savefig(path_data)
plt.close(fig)

figure = aastex.Figure()
figure.add_image(str(path_data), width=None)
figure.add_caption(aastex.NoEscape(
r"Here is a figure caption. \lipsum[5-5]"
))

doc = aastex.Document()
doc.append(title)
doc.append(author)
doc.append(abstract)
doc.append(intro)
doc.append(figure)

path_pdf = pathlib.Path("an_interesting_article.pdf")
doc.generate_pdf(filepath=path_pdf.with_suffix(""))
Expand Down

0 comments on commit 70ccd71

Please sign in to comment.