Triangle plots
Project description
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.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file nj-0.0.5.tar.gz
.
File metadata
- Download URL: nj-0.0.5.tar.gz
- Upload date:
- Size: 10.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b78e8cfd8d1ffb1f026b0129f9fede7015fab18faffa0e3083822505575fcfa3 |
|
MD5 | fdc459de1bbe7d3cafff130208127ac3 |
|
BLAKE2b-256 | 48d456975590e1897e3241d21a35d4bcf63ba3b47f4ed0de0203b247ad2bed39 |
File details
Details for the file nj-0.0.5-py3-none-any.whl
.
File metadata
- Download URL: nj-0.0.5-py3-none-any.whl
- Upload date:
- Size: 11.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 33cf4bcdfa5d3add90e17d3b5b1e056f11c83dade02f3da38518e24261178c37 |
|
MD5 | 1acd248fb294b3b1a70411262fa2902f |
|
BLAKE2b-256 | dadcfc1b706b2c284c2ca99cd8f9dfd5950dc244c8dd7588e02427cee20c3f2c |