From 732ef296eca362e3f8c1e342623210adbf66a899 Mon Sep 17 00:00:00 2001 From: loganthomas Date: Sat, 20 Aug 2022 08:41:09 -0500 Subject: [PATCH] ENH: new feature request clt.catterplot() --- README.rst | 4 ++++ catplotlib/catplot.py | 39 +++++++++++++++++++++++++++++++++++---- setup.py | 1 + 3 files changed, 40 insertions(+), 4 deletions(-) diff --git a/README.rst b/README.rst index c5b7179..44798ee 100644 --- a/README.rst +++ b/README.rst @@ -27,6 +27,10 @@ Features import catplotlib.catplot as clt clt.plot(says='matplotlib + cats = catplotlib') +* And, a third:: + + import catplotlib.catplot as clt + clt.catterplot() Making a Release ---------------- diff --git a/catplotlib/catplot.py b/catplotlib/catplot.py index 38ac10e..1de3f61 100644 --- a/catplotlib/catplot.py +++ b/catplotlib/catplot.py @@ -1,12 +1,15 @@ """Top-level package for catplotlib.""" - -import matplotlib.pyplot as plt -import requests - +import random +import sys from io import BytesIO from urllib.parse import quote +import matplotlib +import matplotlib.pyplot as plt +import requests +CATS = ["🐱", "😹", "😻", "🙀", "😿", "😽", "😸", "😺", "😾", "😼"] +DEFAULT_BACKEND = matplotlib.get_backend() URL = "https://cataas.com/cat" @@ -34,3 +37,31 @@ def plot(says=None): img = plt.imread(data, format="jpg") return plt.imshow(img) + + +def catterplot(n=10): + cats = CATS + + x = [random.random() * 10 for _ in range(n)] + y = [random.random() * 10 for _ in range(n)] + markers = random.choices(cats, k=n) + scatter = plt.scatter(x, y, color="white") + + matplotlib.use("module://mplcairo.macosx") + print(f"Backend is now {matplotlib.get_backend()}") + + prop = matplotlib.font_manager.FontProperties( + fname="/System/Library/Fonts/Apple Color Emoji.ttc" + ) + for x0, y0, cat in zip(x, y, markers): + plt.annotate( + cat, (x0, y0), ha="center", va="bottom", fontsize=30, fontproperties=prop + ) + + plt.title("Catterplot") + plt.xlabel("x-catxis") + plt.ylabel("y-catxis") + plt.xlim(min(x) - 3, max(x) + 3) + plt.ylim(min(y) - 3, max(y) + 3) + + return scatter diff --git a/setup.py b/setup.py index 9b1d2c5..4a33d2e 100755 --- a/setup.py +++ b/setup.py @@ -12,6 +12,7 @@ requirements = [ "matplotlib", + "mplcairo", "requests", ]