diff --git a/.github/workflows/pythontests.yml b/.github/workflows/pythontests.yml index 0a2003f..64882b3 100644 --- a/.github/workflows/pythontests.yml +++ b/.github/workflows/pythontests.yml @@ -30,7 +30,7 @@ jobs: pip install -e . - name: Run test run: | - python -m histoprint + python -m histoprint.test black: diff --git a/histoprint/__init__.py b/histoprint/__init__.py new file mode 100644 index 0000000..7f5f8d3 --- /dev/null +++ b/histoprint/__init__.py @@ -0,0 +1,3 @@ +"""histoprint - Pretty-print histograms to the terminal""" + +from histoprint.formatter import * diff --git a/histoprint.py b/histoprint/formatter.py similarity index 93% rename from histoprint.py rename to histoprint/formatter.py index 6f1a11d..93b1db2 100644 --- a/histoprint.py +++ b/histoprint/formatter.py @@ -1,4 +1,4 @@ -"""Simple function to plot the output of ``numpy.histogram`` to the console""" +"""Module for plotting Numpy-like 1D histograms to the terminal.""" from __future__ import division from six import print_, ensure_str @@ -11,6 +11,8 @@ DEFAULT_FG_COLORS = "0WWWWW" DEFAULT_BG_COLORS = "K00000" +__all__ = ["print_hist", "text_hist", "HistFormatter"] + class Hixel(object): """The smallest unit of a histogram plot.""" @@ -505,46 +507,3 @@ def text_hist(*args, **kwargs): hist = np.histogram(*args, density=density, **kwargs) print_hist(hist, **print_kwargs) return hist - - -def test_hist(): - """Poor man's unit tests.""" - - A = np.random.randn(1000) - 2 - B = np.random.randn(1000) - C = np.random.randn(1000) + 2 - D = np.random.randn(500) * 2 - - text_hist(B) - text_hist( - B, bins=[-5, -3, -2, -1, -0.5, 0, 0.5, 1, 2, 3, 5], title="Variable bin widths" - ) - - histA = np.histogram(A, bins=15, range=(-5, 5)) - histB = np.histogram(B, bins=15, range=(-5, 5)) - histC = np.histogram(C, bins=15, range=(-5, 5)) - histD = np.histogram(D, bins=15, range=(-5, 5)) - histAll = ([histA[0], histB[0], histC[0], histD[0]], histA[1]) - - print_hist(histAll, title="Overlays", labels="ABCDE") - print_hist( - histAll, - title="Stacks", - stack=True, - symbols=" ", - bg_colors="rgbcmy", - labels="ABCDE", - ) - print_hist( - histAll, - title="Summaries", - symbols=r"=|\/", - fg_colors="0", - bg_colors="0", - labels=["AAAAAAAAAAAAAAAA", "B", "CCCCCCCCCCCCC", "D"], - summary=True, - ) - - -if __name__ == "__main__": - test_hist() diff --git a/histoprint/test.py b/histoprint/test.py new file mode 100644 index 0000000..a12b17c --- /dev/null +++ b/histoprint/test.py @@ -0,0 +1,45 @@ +import numpy as np +from histoprint import * + + +def test_hist(): + """Poor man's unit tests.""" + + A = np.random.randn(1000) - 2 + B = np.random.randn(1000) + C = np.random.randn(1000) + 2 + D = np.random.randn(500) * 2 + + text_hist(B) + text_hist( + B, bins=[-5, -3, -2, -1, -0.5, 0, 0.5, 1, 2, 3, 5], title="Variable bin widths" + ) + + histA = np.histogram(A, bins=15, range=(-5, 5)) + histB = np.histogram(B, bins=15, range=(-5, 5)) + histC = np.histogram(C, bins=15, range=(-5, 5)) + histD = np.histogram(D, bins=15, range=(-5, 5)) + histAll = ([histA[0], histB[0], histC[0], histD[0]], histA[1]) + + print_hist(histAll, title="Overlays", labels="ABCDE") + print_hist( + histAll, + title="Stacks", + stack=True, + symbols=" ", + bg_colors="rgbcmy", + labels="ABCDE", + ) + print_hist( + histAll, + title="Summaries", + symbols=r"=|\/", + fg_colors="0", + bg_colors="0", + labels=["AAAAAAAAAAAAAAAA", "B", "CCCCCCCCCCCCC", "D"], + summary=True, + ) + + +if __name__ == "__main__": + test_hist() diff --git a/setup.py b/setup.py index fe87353..8aa6f40 100644 --- a/setup.py +++ b/setup.py @@ -15,14 +15,14 @@ setup( name="histoprint", - version="1.0.1", + version="1.1.0", description=description, long_description=long_description, url="https://github.com/ast0815/histoprint", author="Lukas Koch", author_email="lukas.koch@mailbox.org", license="MIT", - py_modules=["histoprint"], + packages=["histoprint"], install_requires=["numpy>=1.0.0", "six>=1.10.0",], extras_require={}, python_requires=">=2.7",