Last active
May 3, 2019 22:35
-
-
Save batu/e10b5104e91e9c8a7e13e339d9a0133c to your computer and use it in GitHub Desktop.
Altair Show Image
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
img_data = [] | |
img_shape = image.shape | |
# I am sure there is a less loopy way of doing this. | |
for y in range(img_shape[0]): | |
for x in range(img_shape[1]): | |
pixel_color = image[y][x] | |
# Add a .5 offset and convert from RGB to Hex. | |
img_data.append((x +.5, y + .5, rgb2hex(pixel_color))) | |
img_data = np.array(img_data) | |
image_pd = pd.DataFrame({ | |
'x': img_data[:,0], | |
'y': img_data[:,1], | |
"color" : img_data[:,2], | |
}) | |
img_chart = alt.Chart(image_pd).mark_square(size=3, opacity=1).encode( | |
x="x:Q", | |
y="y:Q", | |
color=alt.Color('color', scale=None), | |
).properties( | |
title='We were so busy wondering if we could, we didnt ask if we should.' | |
) | |
img_chart |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment