<jupyter_start><jupyter_text>LegendsThere are different types of legends we can use in our visualization. These legends depend on the geometry of the layer and on the type of the data it is being represented. Legend TypesWhen we set the legend, we have to indicate the type of the legend. Current types are:* Color  * `color-category`  * `color-bins`  * `color-continuous`* Size  * `size-category`  * `size-bins`  * `size-continuous`By default, each of the previous types detects the geometry of the layer. However, we set explicitely the geometry, which is very useful when having several legens to identify the each one type.* Color Category  * [color-category-point](Color-Category-Point)  * [color-category-line](Color-Category-Line)  * [color-category-polygon](Color-Category-Polygon)* Color Bins  * [color-bins-point](Color-Bins-Point)  * [color-bins-line](Color-Bins-Line)  * [color-bins-polygon](Color-Bins-Polygon)* Color Continuous  * [color-continuous-point](Color-Continuous-Point)  * [color-continuous-line](Color-Continuous-Line)  * [color-continuous-polygon](Color-Continuous-Polygon)* Size Category  * [size-category-point](Size-Category-Point)  * [size-category-line](Size-Category-Line)* Size Bins  * [size-bins-point](Size-Bins-Point)  * [size-bins-line](Size-Bins-Line)* Size Continuous  * [size-continuous-point](Size-Continuous-Point)  * [size-continuous-line](Size-Continuous-Line)   Classified by propertyAs we can see in the previous list of legend types, there're two types of legend regarding style: **color** and **size**. * **Color** types represent color style properties: `color` and `strokeColor`.* **Size** types represent size style properties: `width` and `strokeWidth`. Classified by data typeEach color and size legend legend types have three options: **category**, **bins**, and **continuous**.* **Category** legends: for use with **categorical** data.* **Bins** legends: for use with **numeric** data.* **Continuous** legends: for use with **numeric** data.<jupyter_code>from cartoframes.auth import set_default_credentials
from cartoframes.viz import Map, Layer

set_default_credentials('cartovl')<jupyter_output><empty_output><jupyter_text>Default Legend<jupyter_code>Map(
    Layer('populated_places'),
    default_legend=True
)<jupyter_output><empty_output><jupyter_text>Legend Info<jupyter_code>Map(
    Layer(
        'populated_places',
        legend={
            'title': 'Populated Places',
            'description': 'This is a common dataset.',
            'footer': 'Source: CARTO'
        }
    )
)<jupyter_output><empty_output><jupyter_text>Color Legend  Color Category Legend  Color Category PointBy default, the style property represented in the legend is the `color`. But we may want to represent the `strokeColor` property instead, in which case we should specify it by using the 'prop' key in the Legend:<jupyter_code>Map(
    Layer(
        'populated_places',
        'color: ramp(top($adm0name, 5), bold)',
        legend={
            'type': 'color-category-point'
        }
    )
)
Map(
    Layer(
        'populated_places',
        '''
        color: transparent
        width: 10
        strokeWidth: 2
        strokeColor: ramp(top($adm0name, 5), bold)
        ''',
        legend={
            'type': 'color-category-point',
            'prop': 'strokeColor'
        }
    )
)<jupyter_output><empty_output><jupyter_text>Color Category Line<jupyter_code>Map(
    Layer(
        'sfcta_congestion_roads',
        'color: ramp(top($direction, 5), bold)',
        legend={
            'type': 'color-category-line'
        }
    )
)<jupyter_output><empty_output><jupyter_text>Color Category Polygon<jupyter_code>Map(
    Layer(
        'sf_neighborhoods',
        'color: ramp(top($name, 5), bold)',
        legend={
            'type': 'color-category-polygon'
        }
    )
)<jupyter_output><empty_output><jupyter_text>Color Bins LegendFor *points* and *lines*, these legends are equivalent to `color-category-point` and `color-category-line` respectively.  Color Bins Point<jupyter_code>Map(
    Layer(
        'populated_places',
        'color: ramp(globalQuantiles($scalerank, 5), purpor)',
        legend={
            'type': 'color-bins-point'
        }
    )
)<jupyter_output><empty_output><jupyter_text>Color Bins Line<jupyter_code>Map(
    Layer(
        'sfcta_congestion_roads',
        'color: ramp(globalEqIntervals($auto_speed, 5), purpor)',
        legend={
            'type': 'color-bins-line'
        }
    )
)<jupyter_output><empty_output><jupyter_text>Color Bins Polygon<jupyter_code>Map(
    Layer(
        'sf_neighborhoods',
        'color: ramp(globalQuantiles($cartodb_id, 5), purpor)',
        legend={
            'type': 'color-bins-polygon', #'color-bins-polygon'
        }
    )
)<jupyter_output><empty_output><jupyter_text>Color Continuous LegendFor *points* and *lines*, these legends are also equivalent to `color-category-point` and `color-category-line` respectively.  Color Continuous Point<jupyter_code>Map(
    Layer(
        'populated_places',
        'color: ramp(linear($scalerank), purpor)',
        legend={
            'type': 'color-continuous-point'
        }
    )
)<jupyter_output><empty_output><jupyter_text>Color Continuous Line<jupyter_code>Map(
    Layer(
        'sfcta_congestion_roads',
        '''
        color: ramp(linear($auto_speed, 1, 20), bold)
        ''',
        legend={
            'type': 'color-continuous-line'
        }
    )
)<jupyter_output><empty_output><jupyter_text>Color Continuous Polygon<jupyter_code>Map(
    Layer(
        'sf_neighborhoods',
        'color: ramp(linear($cartodb_id), sunset)',
        legend={
            'type': 'color-continuous-polygon',
            'prop': 'color'
        }
    )
)<jupyter_output><empty_output><jupyter_text>Size Legend  Size Category Legend  Size Category Point<jupyter_code>Map(
    Layer(
        'populated_places',
        '''
        width: ramp(buckets($adm_0_cap_name, ["Capital", "City"]), [25, 5])
        strokeWidth: 1
        strokeColor: white
        ''',
        legend={
            'type': 'size-category-point'
        }
    )
)<jupyter_output><empty_output><jupyter_text>Size Category Line<jupyter_code>Map(
    Layer(
        'ne_50m_rivers_lake_centerlines',
        'width: ramp(buckets($featurecla, ["Lake Centerline", "River"]), [4, 1])',
        legend={
            'type': 'size-category-line'
        }
    )
)<jupyter_output><empty_output><jupyter_text>Size Bins Legend  Size Bins Point<jupyter_code>Map(
    Layer(
        'county_points_with_population',
        '''
        width: ramp(globalEqIntervals($estimate_total,5), [2, 40])
        color: opacity(turquoise, 0.8)
        strokeWidth: 0.5
        strokeColor: opacity(blue,0.2)
        ''',
        legend={
            'type': 'size-bins-point'
        }
    )
)<jupyter_output><empty_output><jupyter_text>Size Bins Line<jupyter_code>Map(
    Layer(
        'sfcta_congestion_roads',
        '''
        width: ramp(globalEqIntervals($auto_speed, 5), [1, 10])
        color: opacity(turquoise, 0.8)
        strokeWidth: 0.5
        strokeColor: opacity(blue,0.2)
        ''',
        legend={
            'type': 'size-bins-line'
        }
    )
)<jupyter_output><empty_output><jupyter_text>Size Continuous Legend  Size Continuous Point<jupyter_code>Map(
    Layer(
        'county_points_with_population',
        '''
        width: ramp(linear($estimate_total), [1, 80])
        color: opacity(turquoise, 0.8)
        strokeWidth: 0.5
        strokeColor: opacity(blue,0.4)
        order: asc(width())
        ''',
        legend={
            'type': 'size-continuous-point',
            'title':'Population by County'
        }
    )
)<jupyter_output><empty_output><jupyter_text>Size Continuous Line<jupyter_code>Map(
    Layer(
        'sfcta_congestion_roads',
        '''
        width: ramp(linear($auto_speed), [1, 10])
        color: opacity(turquoise, 0.8)
        strokeWidth: 0.5
        strokeColor: opacity(blue,0.2)
        ''',
        legend={
            'type': 'size-continuous-line'
        }
    )
)<jupyter_output><empty_output><jupyter_text>Multiple layersFor multiple layers visualization, the legends are placed from top to bottom.<jupyter_code>Map([
    Layer(
        'sf_neighborhoods',
        'color: ramp(linear($cartodb_id), sunsetdark)',
        legend={
            'type': 'color-continuous-polygon',
            'prop': 'color'
        }
    ),
    Layer(
        'sfcta_congestion_roads',
        '''
        width: ramp(globalEqIntervals($auto_speed, 5), [1, 10])
        color: opacity(turquoise, 0.8)
        strokeWidth: 0.5
        strokeColor: opacity(blue,0.2)
        ''',
        legend={
            'type': 'size-bins-line'
        }
    )
])
Map([
    Layer(
        'maximum_heat_index',
        'color: ramp(linear($value), purpor)',
        legend={
            'type': 'color-continuous-point',
            'title': 'Heat Index Values'
        }
    ),
    Layer(
        'county_points_with_population',
        '''
        width: ramp(globalEqIntervals($estimate_total,5), [2, 40])
        color: opacity(turquoise, 0.8)
        strokeWidth: 0.5
        strokeColor: opacity(blue,0.2)
        ''',
        legend={
            'type': 'size-continuous-point',
            'title': 'Population by Counti'
        }
    )
])<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup