Plotting emojis

código
Resumen de un googleo interminable
Author

sebastiandres

Published

December 12, 2021

Recently I needed to combine a line chart with an emoji. I googled until exhaustion, but the solutions didn’t work correctly for me. After trying tons of options, the code that did work for me was the following:

def plot_emoji(emoji_path, ax, x, y, zoom=0.35):
    """
    Plots an emoji on a figure.
    Based on:
    https://www.geeksforgeeks.org/emojis-as-markers-in-matplotlib/
    image_path: path to the image
    ax: axis to plot on
    x: x coordinate
    y: y coordinate
    zoom: zoom factor (resizing)
    """
    # reading the image
    image = plt.imread(emoji_path)
    # OffsetBox
    image_box = OffsetImage(image, zoom=zoom)
    # Drawing the image
    ab = AnnotationBbox(image_box, (x, y), frameon=False)
    ax.add_artist(ab)
    return

It doesn’t let you use an emoji directly, but it does work for any image.