Add plot_freq_bar

This commit is contained in:
simon987 2021-06-23 19:37:22 -04:00
parent 3238f92e4d
commit 33e9734991
3 changed files with 35 additions and 3 deletions

3
.gitignore vendored
View File

@ -1,3 +1,4 @@
*.iml
.idea/
*.db
*.db
*.png

30
hexlib/plot.py Normal file
View File

@ -0,0 +1,30 @@
import numpy as np
import matplotlib.pyplot as plt
DATA = [
*["apple"] * 5,
*["banana"] * 12,
*["strawberry"] * 8,
*["pineapple"] * 2,
]
def plot_freq_bar(items, ylabel="frequency", title=""):
item_set, item_counts = np.unique(items, return_counts=True)
plt.bar(item_set, item_counts)
plt.xticks(rotation=35)
plt.ylabel(ylabel)
plt.title(title)
for i, cnt in enumerate(item_counts):
plt.text(x=i, y=cnt / 2, s=cnt, ha="center", color="white")
plt.tight_layout()
if __name__ == '__main__':
plot_freq_bar(DATA, title="My title")
plt.show()

View File

@ -2,7 +2,7 @@ from setuptools import setup
setup(
name="hexlib",
version="1.42",
version="1.43",
description="Misc utility methods",
author="simon987",
author_email="me@simon987.net",
@ -13,6 +13,7 @@ setup(
]},
install_requires=[
"ImageHash", "influxdb", "siphash", "python-dateutil", "redis", "orjson", "zstandard",
"u-msgpack-python", "psycopg2-binary", "fake-useragent", "bs4", "lxml", "nltk"
"u-msgpack-python", "psycopg2-binary", "fake-useragent", "bs4", "lxml", "nltk", "numpy",
"matplotlib"
]
)