Skip to main content

matplotlib Based Publication-Ready Plots

Project description

PyPI version PyPI - Python Version License: MIT GitHub stars GitHub forks

ggpubpy: 'matplotlib' Based Publication-Ready Plots

Matplotlib is an excellent and flexible package for elegant data visualization in Python. However, the default plotting routines often require extensive boilerplate and manual styling before figures are ready for publication. Customizing complex plots can be a barrier for researchers and analysts without advanced plotting expertise.

The ggpubpy library provides a suite of easy-to-use functions for creating and customizing Matplotlib-based, publication-ready plots—complete with built-in statistical tests and automatic p-value or significance star annotations. This project is directly inspired by R's ggpubr package.

📦 PyPI Package: https://pypi.org/project/ggpubpy/
🐙 GitHub Repository: https://github.com/turkalpmd/ggpubpy


Installation and loading

Install the latest stable release from PyPI (recommended):

pip install ggpubpy

Why install from PyPI?

  • ✅ Stable, tested releases
  • ✅ Automatic dependency management
  • ✅ Easy updates with pip install --upgrade ggpubpy
  • ✅ Compatible with virtual environments

Or install the development version directly from GitHub:

pip install git+https://github.com/turkalpmd/ggpubpy.git

Load the package:

import ggpubpy
from ggpubpy import violinggplot, boxggplot, plot_shift
from ggpubpy.datasets import load_iris  # Built-in datasets

Core Features

  • Violin + boxplot + jitter in one call
  • Automatic color palettes with ColorBrewer-inspired defaults
  • Built-in datasets (iris) for quick testing and examples
  • Flexible group comparisons - works with 2-group, 3-group, or more
  • Built-in Kruskal–Wallis & Mann–Whitney U tests (or ANOVA & t-tests for parametric option)
  • Automatic p-value or "star" annotation with dynamic bracket placement
  • Smart p-value formatting - pairwise comparisons show significance stars (*, **, ns), global tests show formatted values (<0.001)
  • Parametric and non-parametric statistical tests with parametric=True/False option
  • Smart test selection - t-test for 2 groups, ANOVA for 3+ groups (parametric mode)
  • Modular, data-driven API: custom labels, ordering, figure sizing

Quick Examples

🎻 Violin plots with boxplots & jitter + statistical tests

3-Group Comparison (All Species)

import ggpubpy
from ggpubpy.datasets import load_iris

# Load the iris dataset
iris = load_iris()

# Create the plot with default colors (automatic palette)
fig, ax = ggpubpy.violinggplot(
    df=iris, 
    x="species", 
    y="sepal_length",
    x_label="Species", 
    y_label="Sepal Length (cm)"
)

Violin Plot Example

2-Group Comparison (Subset Analysis)

# Filter for 2-group comparison
iris_2groups = iris[iris['species'].isin(['setosa', 'versicolor'])]

# Create 2-group comparison plot
fig, ax = ggpubpy.violinggplot(
    df=iris_2groups, 
    x="species", 
    y="sepal_length",
    x_label="Species", 
    y_label="Sepal Length (cm)"
)

Violin Plot 2-Groups

📊 Boxplots with jitter + statistical tests

3-Group Box Plot with Default Colors

# Create boxplot with default automatic colors
fig, ax = ggpubpy.boxggplot(
    df=iris, 
    x="species", 
    y="sepal_length",
    x_label="Species", 
    y_label="Sepal Length (cm)"
)

Box Plot Example

2-Group Box Plot with Statistical Tests

# 2-group comparison with Mann-Whitney U test (non-parametric default)
iris_2groups = iris[iris['species'].isin(['setosa', 'versicolor'])]

fig, ax = ggpubpy.boxggplot(
    df=iris_2groups, 
    x="species", 
    y="sepal_length",
    x_label="Species", 
    y_label="Sepal Length (cm)",
    parametric=False  # Non-parametric tests (default)
)

Box Plot 2-Groups

📈 Shift plots for distribution comparison

Shift plots provide a powerful visualization for comparing two distributions by showing:

  • Half-violin plots showing distribution shapes
  • Box plots with quartiles and outliers
  • Raw data points for transparency
  • Quantile connections (optional) showing how percentiles shift between groups
  • Statistical test results in the title
  • Quantile difference subplot (optional) for detailed quantile analysis

Basic Shift Plot

# Compare two groups with shift plot
iris_2groups = iris[iris['species'].isin(['setosa', 'versicolor'])]
x = iris_2groups[iris_2groups['species'] == 'setosa']['sepal_length'].values
y = iris_2groups[iris_2groups['species'] == 'versicolor']['sepal_length'].values

fig = ggpubpy.plot_shift(
    x, y, 
    paired=False, 
    n_boot=1000,
    percentiles=[10, 50, 90], 
    confidence=0.95,
    show_quantiles=True,  # Show quantile connection lines
    show_quantile_diff=False,  # Hide quantile difference subplot
    x_name="Setosa", 
    y_name="Versicolor"
)

Shift Plot Example

Shift Plot with Quantile Differences

# Same plot but with quantile difference subplot
fig = ggpubpy.plot_shift(
    x, y,
    paired=False,
    show_quantiles=True,
    show_quantile_diff=True,  # Show quantile difference subplot
    x_name="Setosa",
    y_name="Versicolor"
)

Shift Plot with Differences

🎨 Advanced Features

# Custom color palette
custom_palette = {
    "setosa": "#FF6B6B", 
    "versicolor": "#4ECDC4", 
    "virginica": "#45B7D1"
}

fig, ax = ggpubpy.violinggplot(
    df=iris, 
    x="species", 
    y="petal_length",
    x_label="Species", 
    y_label="Petal Length (cm)",
    palette=custom_palette
)

# Parametric tests (ANOVA + t-test instead of Kruskal-Wallis + Mann-Whitney)
fig, ax = ggpubpy.violinggplot(
    df=iris, 
    x="species", 
    y="sepal_length",
    x_label="Species", 
    y_label="Sepal Length (cm)",
    parametric=True
)

# Custom ordering
fig, ax = ggpubpy.violinggplot(
    df=iris, 
    x="species",
    y="petal_width",
    order=["virginica", "versicolor", "setosa"]  # Custom order
)

📊 Built-in Datasets

# Load built-in datasets
iris = ggpubpy.datasets.load_iris()
print(f"Available datasets: {ggpubpy.datasets.list_datasets()}")

# Get recommended color palette for iris species
palette = ggpubpy.datasets.get_iris_palette()
print(palette)  # {'setosa': '#00AFBB', 'versicolor': '#E7B800', 'virginica': '#FC4E07'}

🤝 Contributing

We welcome contributions! This project is designed to be contribution-friendly.

Ways to Contribute:

  • 🐛 Bug reports and feature requests
  • 📖 Documentation improvements
  • 🔧 Code contributions (new features, optimizations, tests)
  • 🎨 New plot types and statistical tests
  • 📊 Additional datasets and examples

Getting Started:

# Clone and setup development environment
git clone https://github.com/turkalpmd/ggpubpy.git
cd ggpubpy
pip install -e .
pip install -r requirements-dev.txt

# Run tests to verify setup
python final_check.py

Getting Help:

  • 🐛 GitHub Issues: Bug reports and feature requests
  • 💬 GitHub Discussions: Questions and community discussion

📚 Support

  • 🐛 GitHub Issues: Bug reports and feature requests
  • 💬 GitHub Discussions: Questions and community discussion
  • API Reference: Complete function documentation in code

License

ggpubpy is released under the MIT License. See LICENSE for details.


📈 Project Status

🎉 PUBLISHED ON PyPI: June 20, 2025
📦 Latest Version: 0.2.0
🌟 Status: Stable and ready for production use
🤝 Contributing: Open for community contributions

Install now: pip install ggpubpy

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

ggpubpy-0.2.0.tar.gz (25.5 kB view details)

Uploaded Source

Built Distribution

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

ggpubpy-0.2.0-py3-none-any.whl (15.6 kB view details)

Uploaded Python 3

File details

Details for the file ggpubpy-0.2.0.tar.gz.

File metadata

  • Download URL: ggpubpy-0.2.0.tar.gz
  • Upload date:
  • Size: 25.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.10

File hashes

Hashes for ggpubpy-0.2.0.tar.gz
Algorithm Hash digest
SHA256 43fc6b4b017a6f4d8dac263605a8217e6e9969f8a2decdb84d0b58cfc88db33f
MD5 46a48de5a4ddeae6a8765a436703d157
BLAKE2b-256 8edea8828cd7474b9d7d622d14594298f27b79327d2e37cf5cb4ee36a218ddb0

See more details on using hashes here.

File details

Details for the file ggpubpy-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: ggpubpy-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 15.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.10

File hashes

Hashes for ggpubpy-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1ea5aaee11799d1bfad9723d67ec99153c9f5e9aa3f6454bd684950e995b9028
MD5 484f9fb8fc7282f46ee3c04d91f921e6
BLAKE2b-256 49fd14450a42edcdd0334dfa124686cb75450431e36b061e581cc7effe840d6e

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