Skip to main content

A pythonic port of the BuenColors R library for handy color palettes.

Project description

PyBuenColors

PyPI version Build Status License

A pythonic port of the BuenColors R package for convenient scientific color palettes and matplotlib styles.

Color palettes are a direct port from the R package, with many based on the wesanderson R package.

Installation

pip install buencolors

Quick Start

Using the Pretty Plot Style

The easiest way to improve your matplotlib plots is to use the included pretty-plot style:

import matplotlib.pyplot as plt
import numpy as np

# Apply the pretty-plot style
plt.style.use('pretty-plot')

# Create a beautiful plot
x = np.linspace(0, 10, 100)
plt.plot(x, np.sin(x), label='sin(x)')
plt.plot(x, np.cos(x), label='cos(x)')
plt.xlabel('x')
plt.ylabel('y')
plt.legend()
plt.show()

Before (default):

Default Style

After (pretty-plot):

Pretty Style

Using Color Palettes

BuenColors automatically registers all palettes as matplotlib colormaps:

import buencolors as bc
import matplotlib.pyplot as plt
import numpy as np

# List available palettes
bc.list_palettes()

# Palettes are available directly as colormaps
plt.style.use('pretty-plot')
data = np.random.randn(100, 100)
plt.imshow(data, cmap='Zissou')
plt.colorbar()
plt.show()

# Or use get_palette() to extract individual colors
colors = bc.get_palette('Zissou')
for i, color in enumerate(colors):
    plt.plot([0, 1], [i, i], color=color, linewidth=10)
plt.show()

Features

Helper Functions

BuenColors provides several utility functions to make your plots publication-ready:

Eject Legend

Move legends outside the plot area to avoid obscuring data:

import matplotlib as plt
import buencolors as bc

# Your plot code here
plt.plot(x, y1, label='Dataset 1')
plt.plot(x, y2, label='Dataset 2')

# Eject the legend to the right
bc.eject_legend()

Eject Legend Example

Rotate X-Tick Labels

Automatically rotate discrete x-tick labels for better readability:

bc.rotate_discrete_xticks()

Rotate XTicks Example

Grab Legend

Extract a legend to a separate figure for independent saving or publication:

# Create a plot with legend
plt.plot(x, y1, label='Dataset 1')
plt.plot(x, y2, label='Dataset 2')
plt.legend()

# Extract legend to separate figure (removes from original by default)
legend_fig = bc.grab_legend()
legend_fig.savefig('legend.pdf', bbox_inches='tight')
plt.savefig('plot.pdf')  # Plot saved without legend

# Or keep legend on original plot
legend_fig = bc.grab_legend(remove=False)
legend_fig.savefig('legend_copy.pdf', bbox_inches='tight')
plt.show()  # Original plot still has legend

Grab Legend Example

Color by Density

Color scatter plot points by their density:

x = np.random.randn(1000)
y = np.random.randn(1000)
density = bc.get_density(x, y)

plt.scatter(x, y, c=density, cmap='viridis', s=5)
plt.colorbar(label='Density')

Density Example

Shuffle Plot Order

Randomize the order of plot elements to avoid overplotting bias:

x_shuffled, y_shuffled, colors_shuffled = bc.shuffle(x, y, colors)
plt.scatter(x_shuffled, y_shuffled, c=colors_shuffled)

Shuffle Example

Number to Color

Map numerical values to colors from a palette:

values = [1, 2, 3, 4, 5]
colors = bc.number_to_color(values, palette='Zissou')

Number to Color Example

Single-Cell Analysis

BuenColors provides specialized functions for single-cell analysis visualization, designed to work seamlessly with Scanpy and AnnData objects.

Installation for Single-Cell Features

To use the single-cell features, install with scanpy and anndata:

pip install buencolors scanpy anndata

Clean UMAP Visualization

The clean_umap() function creates publication-ready UMAP plots with minimal decorations:

import scanpy as sc
import buencolors as bc
import matplotlib.pyplot as plt

# Load example dataset
adata = sc.datasets.pbmc3k_processed()

# Create a clean UMAP colored by cell type
with plt.style.context('pretty-plot'):
    bc.clean_umap(adata, color='louvain', palette='lawhoops')

Features of clean_umap():

  • Minimal decorations: No borders, ticks, or frame

  • Custom L-shaped axis indicators: Small arrows showing UMAP dimensions

  • Auto-ejected legend: Automatically positioned to the right to avoid obscuring data

  • Shuffled cells: Randomizes plotting order to avoid non-random ordering artifacts

Clean UMAP Example

Examples

For detailed examples and interactive notebooks, see the documentation or the docs/examples directory.

Available Palettes

All Palettes

License

This project is licensed under the MIT License.

Credits

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

buencolors-1.0.0.tar.gz (6.0 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

buencolors-1.0.0-py3-none-any.whl (23.6 kB view details)

Uploaded Python 3

File details

Details for the file buencolors-1.0.0.tar.gz.

File metadata

  • Download URL: buencolors-1.0.0.tar.gz
  • Upload date:
  • Size: 6.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.16 {"installer":{"name":"uv","version":"0.9.16","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for buencolors-1.0.0.tar.gz
Algorithm Hash digest
SHA256 d1ae6a959127aa2187f5a42390227cbfe19616489d3f600e8293af9b74a2c68f
MD5 5dd596a85cd652732fcc69cd9ad044fa
BLAKE2b-256 97f0b2dbd22de855d7d345296f9cee9fe7ca4697566a457daa80b290bf0e2629

See more details on using hashes here.

File details

Details for the file buencolors-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: buencolors-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 23.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.16 {"installer":{"name":"uv","version":"0.9.16","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for buencolors-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 68cd5a74981a5f5592c7946744c573789a677badce7ec84ab09803ebdb3c15fc
MD5 b49e1f596891bea65ce6abfb84fee23f
BLAKE2b-256 04c1a4de189a1e5276898b8da518f3118266af633a7bbee04e119da0006179e8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page