Icons layer

The icons layer displays images associated to taxid values.

Icons are specified by either an http or https URL, a data URI, or a file path.

In the following example we use an svg icon encoded into a data URI. We specify an icon width, height, a vertical anchor and a color to tint it (color only works for certain type of SVG images).

import polars as pl
from pylifemap import Lifemap

# Load iucn dataset
iucn = pl.read_parquet(
    "https://raw.githubusercontent.com/Lifemap-ToL/pylifemap/main/data/iucn.parquet"
).sample(n=5000)

(
    Lifemap(iucn).layer_icons(
        icon="data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%2024%2024%22%3E%3Cpath%20d%3D%22M12%2C11.5A2.5%2C2.5%200%200%2C1%209.5%2C9A2.5%2C2.5%200%200%2C1%2012%2C6.5A2.5%2C2.5%200%200%2C1%2014.5%2C9A2.5%2C2.5%200%200%2C1%2012%2C11.5M12%2C2A7%2C7%200%200%2C0%205%2C9C5%2C14.25%2012%2C22%2012%2C22C12%2C22%2019%2C14.25%2019%2C9A7%2C7%200%200%2C0%2012%2C2Z%22%20style%3D%22fill%3A%20%23FFFFFF%22%2F%3E%3C%2Fsvg%3E",
        y_anchor=1.0,
        width=24,
        height=24,
        color="#FF4488",
    ).show()
)
Warning: 48 taxids have not been found in Lifemap database.
Warning: 1 duplicated taxids have been found in the data: [1125009].

The icon parameter can also be a data column containing image URLs or image file paths. Here we also use the scale argument to resize the icons by a given factor.

d = pl.DataFrame({
        "taxid": [
            "1005039",
            "9544",
            "41956",
            "35128",
            "74311",
        ],
        "name": [
            "Fimbriimonas ginsengisoli",
            "Macaca mulatta",
            "Amanita muscaria",
            "Thalassiosira pseudonana",
            "Brevundimonas bacteroides",
        ],
        "imageurl": [
            "https://images.phylopic.org/images/6767b093-d375-48c2-b4f2-9215b76ea08d/thumbnail/64x64.png",
            "https://images.phylopic.org/images/4e9c5666-79cc-4766-a7d3-d547514b0d77/thumbnail/64x64.png",
            "https://images.phylopic.org/images/f722ba34-03d4-4b90-8409-e02829a3c5d4/thumbnail/64x64.png",
            "https://images.phylopic.org/images/ebff2e9f-3091-4ad6-a7b2-f39a77d3a960/thumbnail/64x64.png",
            "https://images.phylopic.org/images/8fbb3dd3-24ff-4e96-b41c-92b334ff4560/thumbnail/64x64.png",
        ],
    })

Lifemap(d, theme="lightgrey").layer_icons(icon="imageurl", scale=0.8, popup=True).show()

For a detailed list of layer_icons arguments you can take a look at its documentation.