Image#
Image marks allow external images, such as icons or photographs, to be included in Altair visualizations. Image files such as PNG or JPG images are loaded from provided URLs.
Image Mark Properties#
An image
mark can contain any standard mark properties
and the following special properties:
Click to show table
Property |
Type |
Description |
---|---|---|
url |
The URL of the image file for image marks. |
|
aspect |
anyOf( |
Whether to keep aspect ratio of image marks. |
align |
The horizontal alignment of the text or ranged marks (area, bar, image, rect, rule). One of Note: Expression reference is not supported for range marks. |
|
baseline |
anyOf( |
For text marks, the vertical text baseline. One of For range marks, the vertical alignment of the marks. One of Note: Expression reference is not supported for range marks. |
Scatter Plot with Image Marks#
import altair as alt
import pandas as pd
source = pd.DataFrame.from_records(
[
{
"x": 0.5,
"y": 0.5,
"img": "https://vega.github.io/vega-datasets/data/ffox.png",
},
{
"x": 1.5,
"y": 1.5,
"img": "https://vega.github.io/vega-datasets/data/gimp.png",
},
{
"x": 2.5,
"y": 2.5,
"img": "https://vega.github.io/vega-datasets/data/7zip.png",
},
]
)
alt.Chart(source).mark_image(width=50, height=50).encode(x="x", y="y", url="img")