Last active
February 26, 2018 23:43
-
-
Save etra0/123665575cfeadb4bcbbdc0db9f585a4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import numpy as np | |
import sys | |
import matplotlib.pyplot as plt | |
import matplotlib as mpl | |
import matplotlib.font_manager as fm | |
from scipy.misc import imread | |
from PIL import Image | |
f = fm.FontProperties(fname='/System/Library/Fonts/Times.dfont') | |
def transform_to_data(img, cmap='viridis'): | |
loaded_image = Image.open(img) | |
w, h = loaded_image.size | |
c_s = 500 # custom size | |
loaded_image = loaded_image.resize((c_s, h*c_s//w), Image.ANTIALIAS) | |
loaded_image = np.asarray(loaded_image) | |
print(loaded_image.shape) | |
loaded_image = np.squeeze(loaded_image[:, :, 3]) | |
loaded_image = np.flip(np.transpose(loaded_image), 1) | |
x, y = loaded_image.nonzero() | |
mask = np.random.choice(len(x), int(len(x)*0.0018)) | |
X = x[mask] | |
Y = y[mask] | |
scale=1.5 | |
s = np.random.uniform(size=X.shape[0])*100 | |
cmap = plt.get_cmap(cmap) | |
c = [cmap(np.random.rand()) for _ in range(X.shape[0])] | |
return {"x": X, "y": Y, "s": s, "color": c} | |
fig, ax = plt.subplots(figsize=np.array((815, 312))//80) | |
data1 = transform_to_data("r.png", "viridis") | |
data2 = transform_to_data("c.png", "RdPu") | |
# move data | |
data2['x'] += (data1['x'].max()*1.5).astype("int64") | |
ax.text(data1['x'].max()*1.3, -100, "&", fontproperties=f, fontsize=100, va='bottom', ha='center', zorder=1) | |
ax.grid(False) | |
ax.set(xticks=[], yticks=[]) | |
ax.scatter(**data1, alpha=0.8, zorder=2) | |
ax.scatter(**data2, alpha=0.8, zorder=0) | |
plt.axis('equal') | |
plt.savefig("final_boss.png", dpi=300) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment