mirror of
https://github.com/simon987/hexlib.git
synced 2025-04-19 17:56:43 +00:00
Add plot_freq_bar
This commit is contained in:
parent
3238f92e4d
commit
33e9734991
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,4 @@
|
|||||||
*.iml
|
*.iml
|
||||||
.idea/
|
.idea/
|
||||||
*.db
|
*.db
|
||||||
|
*.png
|
30
hexlib/plot.py
Normal file
30
hexlib/plot.py
Normal 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()
|
||||||
|
|
||||||
|
|
5
setup.py
5
setup.py
@ -2,7 +2,7 @@ from setuptools import setup
|
|||||||
|
|
||||||
setup(
|
setup(
|
||||||
name="hexlib",
|
name="hexlib",
|
||||||
version="1.42",
|
version="1.43",
|
||||||
description="Misc utility methods",
|
description="Misc utility methods",
|
||||||
author="simon987",
|
author="simon987",
|
||||||
author_email="me@simon987.net",
|
author_email="me@simon987.net",
|
||||||
@ -13,6 +13,7 @@ setup(
|
|||||||
]},
|
]},
|
||||||
install_requires=[
|
install_requires=[
|
||||||
"ImageHash", "influxdb", "siphash", "python-dateutil", "redis", "orjson", "zstandard",
|
"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"
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user