# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# +
from cartoframes.auth import set_default_context
from cartoframes.viz import Map, Layer, Source, Style, Legend

set_default_context('https://cartovl.carto.com/')

# +
# Legend color
map = Map(
    Layer(
        Source('populated_places'),
        Style('color: ramp(top($adm0name, 5), bold)'),
        legend=Legend({
            'type': 'color-category',
            'title': '[TITLE]',
            'description': '[description]',
            'footer': '[footer]'
        })
    )
)

# Legend color + sugar
Map(
    Layer(
        'populated_places',
        'color: ramp(top($adm0name, 5), bold)',
        legend={
            'type': 'color-category',
            'title': '[TITLE]',
            'description': '[description]',
            'footer': '[footer]'
        }
    )
)
# -

# Legend strokeColor
Map(
    Layer(
        'populated_places',
        'color: transparent strokeWidth: 1 strokeColor: ramp(top($adm0name, 5), bold)',
        legend={
            'type': 'color-category',
            'prop': 'strokeColor',
            'title': '[TITLE]',
            'description': '[description]'
        }
    )
)

# Legend: only info
Map(
    Layer(
        'populated_places',
        legend={
            'title': '[TITLE]',
            'description': '[description]',
            'footer': '[footer]'
        }
    )
)

# Legend: color
Map(
    Layer(
        'populated_places',
        legend={
            'type': 'color-category'
        }
    )
)

# Legend: size
Map(
    Layer(
        'populated_places',
        '''
        width: ramp($pop_max, [0, 50])
        strokeWidth: 1
        strokeColor: opacity(white, 0.4)
        ''',
        legend={
            'type': 'size-bins'
        }
    )
)

# Legend: complete
Map(
    Layer(
        'SELECT * FROM populated_places WHERE adm0name = \'Spain\'',
        'color: ramp(globalQuantiles($pop_max, 5), reverse(purpor))',
        legend={
            'type': 'color-category',
            'title': 'Population'
        }
    )
)

Map(
    Layer('populated_places'),
    default_legend=True
)

StarcoderdataJupyterScriptsDedupFiltered