diff --git a/figpager/figpager.py b/figpager/figpager.py index 28ecc9d..95f3313 100755 --- a/figpager/figpager.py +++ b/figpager/figpager.py @@ -13,6 +13,7 @@ import inspect import os +# backend for display in GitHub Actions if os.environ.get('DISPLAY','') == '': import matplotlib as mpl print('no display found. Using non-interactive Agg backend') @@ -97,6 +98,7 @@ def __init__( overwrite=False, sharex=False, sharey=False, + draft=True, ): """ @@ -125,7 +127,8 @@ def __init__( direction: (string) (optional) subplot creation direction. Default is left-to-right. overwrite: (boolean) (optional) Boolean on whether to overwrite existing output. Default is True sharex: share x axes in subplots. Default is False - sharey:share y axes in subplots.Default is False + sharey:share y axes in subplots. Default is False + draft: Add draft stamp if available from ini. Default is True """ # obtain the caller path @@ -225,6 +228,7 @@ def __init__( self.width_ratios = width_ratios self.sharex = sharex self.sharey = sharey + self.draft = draft # figure attributes self.fig = None @@ -1009,6 +1013,8 @@ def draw_page(self): # add any layout set text here for k in self.config["Text"].keys(): if self._parse_option("Text", k, "text") is not None: + if 'draft' in self._parse_option("Text", k, "text").lower(): + if not self.draft: continue self._text_from_label("Text", k, self._parse_option("Text", k, "text")) # add any layout set images here @@ -1022,6 +1028,9 @@ def draw_page(self): # add any layout set watermarks here for k in self.config["Watermark"].keys(): if self._parse_option("Watermark", k, "text") is not None: + # check for draft watermark status and whether user has overridden it + if 'draft' in self._parse_option("Watermark", k, "text").lower(): + if not self.draft: continue self._text_from_label( "Watermark", k, self._parse_option("Watermark", k, "text") ) diff --git a/figpager/page_layout/Report.ini b/figpager/page_layout/report.ini similarity index 100% rename from figpager/page_layout/Report.ini rename to figpager/page_layout/report.ini diff --git a/setup.py b/setup.py index 44010d2..ecaaa66 100755 --- a/setup.py +++ b/setup.py @@ -16,7 +16,7 @@ def read(fname): setup( name="figpager", - version="0.25", + version="0.26", author="Eben Pendleton", author_email="4080051+ebenp@users.noreply.github.com", url="https://github.com/ebenp/figpager", diff --git a/tests/figpager_no_draft.png b/tests/figpager_no_draft.png new file mode 100644 index 0000000..df974bb Binary files /dev/null and b/tests/figpager_no_draft.png differ diff --git a/tests/figpager_no_draft_02.png b/tests/figpager_no_draft_02.png new file mode 100644 index 0000000..06afe89 Binary files /dev/null and b/tests/figpager_no_draft_02.png differ diff --git a/tests/out.pdf b/tests/out.pdf index 190f7a1..6a95e10 100644 Binary files a/tests/out.pdf and b/tests/out.pdf differ diff --git a/tests/out_2.pdf b/tests/out_2.pdf index c6cc4b6..5412be4 100644 Binary files a/tests/out_2.pdf and b/tests/out_2.pdf differ diff --git a/tests/out_3.pdf b/tests/out_3.pdf index 460dc49..38a3ae0 100644 Binary files a/tests/out_3.pdf and b/tests/out_3.pdf differ diff --git a/tests/out_4.pdf b/tests/out_4.pdf index 4b87dfe..b67e608 100644 Binary files a/tests/out_4.pdf and b/tests/out_4.pdf differ diff --git a/tests/test_1.py b/tests/test_1.py index bc97ba2..0f72307 100755 --- a/tests/test_1.py +++ b/tests/test_1.py @@ -21,7 +21,7 @@ def test_main(): "letter", 3, 2, - layout="Report", + layout="report", outfile=outfile, orientation="portrait", height_ratios=[1, 1, 2], diff --git a/tests/test_5.py b/tests/test_5.py new file mode 100755 index 0000000..a95400b --- /dev/null +++ b/tests/test_5.py @@ -0,0 +1,115 @@ +# Test for multipage support + +# Plots from: https://matplotlib.org/3.2.1/gallery/images_contours_and_fields/plot_streamplot.html#sphx-glr-gallery-images-contours-and-fields-plot-streamplot-py +import os + +import numpy as np + +from figpager import FigPager + + +def test_main(): + # Initalize with a configuration that controls page margins + # and plot spacing + # Initalize with a page size and number of plots + + # Initalize with an output file + outfile = "./tests/figpager_no_draft.png" + + # plots an image from http://www.metmuseum.org/art/collection/search/334348 CC0 1.0 Public Domain + fp = FigPager( + "letter", + 3, + 2, + layout="report", + outfile=outfile, + orientation="portrait", + height_ratios=[1, 1, 2], + overwrite=True, + transparent=False, + draft=False + ) + + w = 3 + Y, X = np.mgrid[-w:w:100j, -w:w:100j] + U = -1 - X ** 2 + Y + V = 1 + X - Y ** 2 + speed = np.sqrt(U ** 2 + V ** 2) + + ax0 = fp.add_subplot() + ax0.streamplot(X, Y, U, V, density=[0.5, 1]) + ax0.set_title("Varying Density") + + fp.text_from_label("Figure Title", "Figure 1") + + # Varying color along a streamline + ax1 = fp.add_subplot() + strm = ax1.streamplot(X, Y, U, V, color=U, linewidth=2, cmap="autumn") + fp.fig.colorbar(strm.lines) + ax1.set_title("Varying Color") + + # Varying line width along a streamline + ax2 = fp.add_subplot() + lw = 5 * speed / speed.max() + ax2.streamplot(X, Y, U, V, density=0.6, color="k", linewidth=lw) + ax2.set_title("Varying Line Width") + + # Controlling the starting points of the streamlines + seed_points = np.array([[-2, -1, 0, 1, 2, -1], [-2, -1, 0, 1, 2, 2]]) + + ax3 = fp.add_subplot() + strm = ax3.streamplot( + X, Y, U, V, color=U, linewidth=2, cmap="autumn", start_points=seed_points.T + ) + fp.fig.colorbar(strm.lines) + ax3.set_title("Controlling Starting Points") + + # Displaying the starting points with blue symbols. + ax3.plot(seed_points[0], seed_points[1], "bo") + ax3.set(xlim=(-w, w), ylim=(-w, w)) + + # Create a mask + mask = np.zeros(U.shape, dtype=bool) + mask[40:60, 40:60] = True + U[:20, :20] = np.nan + U = np.ma.array(U, mask=mask) + + ax4 = fp.add_subplot(gs=fp.gs[2:, :]) + ax4.streamplot(X, Y, U, V, color="r") + ax4.set_title("Streamplot with Masking") + + ax4.imshow( + ~mask, + extent=(-w, w, -w, w), + alpha=0.5, + interpolation="nearest", + cmap="gray", + aspect="auto", + ) + + # this is the next page. Currently starts at [0, 0] + + Y, X = np.mgrid[-w:w:100j, -w:w:100j] + U = -1 - X ** 2 + Y + V = 1 + X - Y ** 2 + + ax3 = fp.add_subplot() + strm = ax3.streamplot( + X, Y, U, V, color=U, linewidth=2, cmap="autumn", start_points=seed_points.T + ) + fp.fig.colorbar(strm.lines) + ax3.set_title("Controlling Starting Points") + + # Displaying the starting points with blue symbols. + ax3.plot(seed_points[0], seed_points[1], "bo") + ax3.set(xlim=(-w, w), ylim=(-w, w)) + + # close the figure + fp.close() + print("outfile: " + fp.outfile) + + print("--Done!--") + + +if __name__ == "__main__": + test_main()