Skip to content

brianckeegan/memeplotlib

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

48 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PyPI version conda-forge version Python versions License: MIT

memeplotlib logotype

Memes with Python's matplotlib. Create image macro memes using matplotlib for rendering and the memegen API for template discovery.

Installation

pip:

pip install memeplotlib

conda:

conda install -c conda-forge memeplotlib

Quick Start

import memeplotlib as memes

# One-liner meme from a memegen template
memes.meme("buzz", "memes", "memes everywhere")

buzz meme example

# Save to file
memes.meme("doge", "such code", "very bug", savefig="meme.png", show=False)

doge meme example

Features

Functional API

import memeplotlib as memes

# Customize text styling
memes.meme("drake", "writing tests", "shipping to prod",
           font="impact", color="yellow")

drake functional example

# Get figure/axes back for further customization
fig, ax = memes.meme("distracted", "my project", "new framework", "me",
                      show=False)

distracted functional example

# Use a local image as template
memes.meme("/path/to/image.jpg", "top text", "bottom text")

Object-Oriented API

from memeplotlib import Meme

# Step by step
m = Meme("drake")
m.top("reading docs")
m.bottom("guessing until it works")
m.save("output.png")

drake OO example

# Or chained
Meme("buzz").top("python").bottom("python everywhere").show()

buzz OO chained example

Memify Existing Plots

Turn any matplotlib figure into a meme:

import matplotlib.pyplot as plt
import memeplotlib as memes

fig, ax = plt.subplots()
ax.plot([1, 2, 3], [1, 4, 9])
memes.memify(fig, "stonks")

memify stonks example

Global Configuration

import memeplotlib as memes

memes.config.font = "comic"
memes.config.color = "yellow"
memes.config.fontsize = 120  # base font size in points
memes.config.style = "none"  # don't auto-uppercase

memes.meme("buzz", "custom defaults", "applied everywhere", show=False)

global configuration example

Template Discovery

from memeplotlib import TemplateRegistry

reg = TemplateRegistry()
results = reg.search("dog")
all_templates = reg.list_all()

Documentation

Full documentation including a tutorial, user guide, and API reference is available at brianckeegan.github.io/memeplotlib.

To build the docs locally:

pip install -e ".[docs]"
cd docs
make html
open _build/html/index.html

How It Works

  1. Templates are fetched from the memegen API (blank background images + metadata)
  2. Images are cached locally for offline reuse
  3. Text is rendered using matplotlib's text system with patheffects.Stroke for the classic outlined meme look
  4. An Impact-like font (Anton) is bundled as a fallback for systems where Impact isn't installed

Dependencies

  • matplotlib >= 3.0.0
  • requests
  • numpy
  • Pillow
  • platformdirs

Requires Python 3.10+.

License

MIT

About

Memes with Python's matplotlib

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages