Skip to content

Commit

Permalink
Turn module into a proper package.
Browse files Browse the repository at this point in the history
  • Loading branch information
ast0815 committed May 16, 2020
1 parent 29b657b commit 009df71
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 47 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pythontests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
pip install -e .
- name: Run test
run: |
python -m histoprint
python -m histoprint.test
black:

Expand Down
3 changes: 3 additions & 0 deletions histoprint/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"""histoprint - Pretty-print histograms to the terminal"""

from histoprint.formatter import *
47 changes: 3 additions & 44 deletions histoprint.py → histoprint/formatter.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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."""
Expand Down Expand Up @@ -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()
45 changes: 45 additions & 0 deletions histoprint/test.py
Original file line number Diff line number Diff line change
@@ -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()
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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="[email protected]",
license="MIT",
py_modules=["histoprint"],
packages=["histoprint"],
install_requires=["numpy>=1.0.0", "six>=1.10.0",],
extras_require={},
python_requires=">=2.7",
Expand Down

0 comments on commit 009df71

Please sign in to comment.