PlotBin
The PlotBin package is a Python library, currently at version 3.1.8, developed by Michele Cappellari. It provides specialized utilities for plotting binned maps and other general two-dimensional data visualizations. Primarily aimed at scientific research and development, particularly in fields like astronomy and astrophysics, its documentation is embedded within the source code file headers. The project maintains an active status with irregular but consistent updates, with the latest release in September 2025.
Common errors
-
ModuleNotFoundError: No module named 'plotbin.display_bins'
cause The `plotbin` package or the `display_bins` submodule is not installed or the import path is incorrect. This can happen if an older version of plotbin was installed or the package structure changed.fixVerify that `plotbin` is installed (`pip show plotbin`). If installed, ensure your import statement matches the current package structure, e.g., `from plotbin.display_bins import display_bins`. If the error persists, consider reinstalling with `pip install --upgrade plotbin` to get the latest version. -
TypeError: display_bins() got an unexpected keyword argument 'ax'
cause The `display_bins` function (or a similar plotting function) was called with an `ax` argument, but that specific version or function might not support directly passing a Matplotlib Axes object, or expects it as a positional argument.fixCheck the function signature in the source code's file headers for the `display_bins` function to understand its expected arguments. If an `ax` argument is not supported, you might need to create the plot on the current active Axes or manually integrate it with Matplotlib's object-oriented interface. Update `plotbin` if a newer version supports the `ax` argument.
Warnings
- breaking Older versions of 'plotbin' might have used different import paths, potentially leading to `ImportError`. A changelog from a related project (pafit) noted 'Changed imports for plotbin as package'.
- gotcha The PlotBin library is distributed under a restrictive, non-commercial license. Permission to use is for non-commercial purposes only, and redistribution of the code is not allowed.
- gotcha Official documentation for PlotBin is primarily contained within the file headers of the source code, rather than a separate documentation website or extensive README.
Install
-
pip install plotbin
Imports
- display_bins
import plotbin.display_bins
from plotbin.display_bins import display_bins
Quickstart
import numpy as np
from plotbin.display_bins import display_bins
import matplotlib.pyplot as plt
# Simulate some binned data (e.g., from a galaxy observation)
x = np.random.rand(100) * 10
y = np.random.rand(100) * 10
z = np.sin(x/2) + np.cos(y/2) + np.random.rand(100) * 0.5
# Create a simple display_bins plot
fig, ax = plt.subplots(figsize=(7, 6))
display_bins(x, y, z, ax=ax, cmap='viridis', textcolor='white')
ax.set_title('Example Binned Map with PlotBin')
ax.set_xlabel('X-coordinate')
ax.set_ylabel('Y-coordinate')
plt.colorbar(ax.collections[0], ax=ax, label='Value')
plt.show()