histoprint

2.6.0 · active · verified Sat Apr 11

histoprint is a Python library that provides pretty-printing of NumPy (and other compatible) histograms directly to the console. It leverages terminal color codes and Unicode characters to create visually appealing histogram representations. Currently at version 2.6.0, it follows a regular release cadence with updates typically adding features, improving compatibility, and addressing minor issues.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to generate sample data using NumPy and then visualize it as histograms in the console using `histoprint.text_hist` for single-array input and `histoprint.print_hist` for displaying multiple or pre-computed NumPy histograms, including stacked visualizations.

import numpy as np
from histoprint import text_hist, print_hist

# Create some sample data
A = np.random.randn(1000) - 2
B = np.random.randn(1000)
C = np.random.randn(1000) + 2

# Use text_hist for a single array (wraps numpy.histogram)
print('--- Single Histogram (text_hist) ---')
text_hist(B, bins=[-5, -3, -2, -1, -0.5, 0, 0.5, 1, 2, 3, 5], title="Variable bin widths")

# Create NumPy histograms manually for print_hist
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))

# print_hist can print multiple histograms at once
print('\n--- Overlapping Histograms (print_hist) ---')
print_hist(([histA[0], histB[0], histC[0]], histA[1]), title="Overlays", labels="ABC")

print('\n--- Stacked Histograms (print_hist) ---')
print_hist(([histA[0], histB[0], histC[0]], histA[1]), title="Stacks", stack=True, labels="ABC", bg_colors="rgb")

view raw JSON →