nj
Triangle plots
To install: pip install nj
Overview
The nj package provides tools for creating triangle plots, which are useful for visualizing and analyzing the distributions and correlations between multiple variables in a dataset. It includes functionality for plotting histograms, 2D histograms, and error ellipses, as well as enhancing plots with quantiles and truth values for comparative analysis.
Main Features
- corner: Generates a corner plot (or a pair plot) that shows all the pairwise scatter plots of the variables on the off-diagonals, the histogram of each variable on the diagonal, and optionally overlays contours and points.
- hist2d: Plots a 2-dimensional histogram or density plot.
- error_ellipse: Plots an error ellipse based on a covariance matrix, useful for visualizing confidence intervals on scatter plots.
Installation
To install nj, use pip:
pip install nj
Usage Examples
Creating a Corner Plot
To create a corner plot to visualize the distribution of and correlation between multiple variables:
import numpy as np
import matplotlib.pyplot as plt
from nj import corner
# Generate some synthetic data
data = np.random.randn(1000, 3) # 1000 samples of 3 variables
# Create a corner plot
fig = corner(data, labels=['X', 'Y', 'Z'], show_titles=True, quantiles=[0.16, 0.5, 0.84])
plt.show()
Plotting a 2D Histogram
To plot a 2-dimensional histogram of two variables:
import numpy as np
import matplotlib.pyplot as plt
from nj import hist2d
# Generate some synthetic data
x = np.random.randn(1000)
y = np.random.randn(1000)
# Create a 2D histogram
fig, ax = plt.subplots()
hist2d(x, y, ax=ax, plot_contours=True)
plt.show()
Adding an Error Ellipse
To add an error ellipse to a scatter plot:
import numpy as np
import matplotlib.pyplot as plt
from nj import error_ellipse
# Generate some synthetic data
data = np.random.multivariate_normal([0, 0], [[1, 0.5], [0.5, 1]], size=1000)
x, y = data.T
# Plot the data
fig, ax = plt.subplots()
ax.scatter(x, y, s=5)
# Calculate the covariance and plot the error ellipse
cov = np.cov(data, rowvar=False)
error_ellipse([0, 0], cov, ax=ax, edgecolor='red')
plt.show()
Documentation
Function: corner
Generates a comprehensive corner plot. This function is highly customizable with numerous parameters to adjust the appearance and behavior of the plot, including options for displaying quantiles, adjusting the histogram scaling, and plotting contours or data points.
Function: hist2d
Creates a 2-dimensional histogram or density plot. This function allows for significant customization, including the choice of bin size, colormap, and whether to include contours or data points.
Function: error_ellipse
Plots an error ellipse at a specified point given its covariance matrix. This function is useful for visualizing uncertainty in two-dimensional measurements.
Contributing
Contributions to nj are welcome! Please feel free to submit pull requests or raise issues on the project's GitHub page.
Release files for nj 0.0.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| nj-0.0.5.tar.gz | 10.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| nj-0.0.5-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 21.7 kB
Release files / nj-0.0.5.tar.gz
| Download URL | nj-0.0.5.tar.gz |
|---|---|
| Size | 10.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b78e8cfd8d1ffb1f026b0129f9fede7015fab18faffa0e3083822505575fcfa3
|
|
BLAKE2b-256 checksum How to use checksums |
48d456975590e1897e3241d21a35d4bcf63ba3b47f4ed0de0203b247ad2bed39
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.10.13
|
Release files / nj-0.0.5-py3-none-any.whl
| Download URL | nj-0.0.5-py3-none-any.whl |
|---|---|
| Size | 11.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
33cf4bcdfa5d3add90e17d3b5b1e056f11c83dade02f3da38518e24261178c37
|
|
BLAKE2b-256 checksum How to use checksums |
dadcfc1b706b2c284c2ca99cd8f9dfd5950dc244c8dd7588e02427cee20c3f2c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.10.13
|