Skip to content

Instantly share code, notes, and snippets.

@batu
Last active May 3, 2019 22:35
Show Gist options
  • Save batu/e10b5104e91e9c8a7e13e339d9a0133c to your computer and use it in GitHub Desktop.
Save batu/e10b5104e91e9c8a7e13e339d9a0133c to your computer and use it in GitHub Desktop.
Altair Show Image
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