Metadata-Version: 2.4
Name: nj
Version: 0.0.5
Summary: Triangle plots
Home-page: https://github.com/t-c-w/nj
Author: Thor Whalen
License: apache-2.0
Platform: any
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: license-file

# 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:

```bash
pip install nj
```

## Usage Examples

### Creating a Corner Plot

To create a corner plot to visualize the distribution of and correlation between multiple variables:

```python
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:

```python
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:

```python
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.
