Created
October 24, 2017 19:27
-
-
Save CatherineH/ca3e74d3d2952957c6da8468488b54af to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from os.path import join, dirname, abspath | |
from matplotlib import pyplot | |
from matplotlib.cbook import get_sample_data | |
from numpy import linspace | |
from numpy.core.umath import pi | |
from numpy.ma import sin | |
# poo-mark came from emojipedia: | |
# https://emojipedia-us.s3.amazonaws.com/thumbs/120/apple/96/pile-of-poo_1f4a9.png | |
poo_img = pyplot.imread(get_sample_data(join(dirname(abspath(__file__)), "poo-mark.png"))) | |
x = linspace(0, 2*pi, num=10) | |
y = sin(x) | |
fig, ax = pyplot.subplots() | |
plot = ax.plot(x, y, linestyle="-") | |
ax_width = ax.get_window_extent().width | |
fig_width = fig.get_window_extent().width | |
fig_height = fig.get_window_extent().height | |
poo_size = ax_width/(fig_width*len(x)) | |
poo_axs = [None for i in range(len(x))] | |
for i in range(len(x)): | |
loc = ax.transData.transform((x[i], y[i])) | |
poo_axs[i] = fig.add_axes([loc[0]/fig_width-poo_size/2, loc[1]/fig_height-poo_size/2, | |
poo_size, poo_size], anchor='C') | |
poo_axs[i].imshow(poo_img) | |
poo_axs[i].axis("off") | |
fig.savefig("poo_plot.png") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment