File: pattern.md

package info (click to toggle)
folium 0.20.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,168 kB
  • sloc: python: 4,489; makefile: 134; sh: 26
file content (54 lines) | stat: -rw-r--r-- 1,179 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
```{code-cell} ipython3
---
nbsphinx: hidden
---
import folium
import folium.plugins
```

# Pattern plugins

We have two pattern plugin classes: `StripePattern` and `CirclePattern`.

```{code-cell} ipython3
import requests

m = folium.Map([40.0, -105.0], zoom_start=6)

stripes = folium.plugins.pattern.StripePattern(angle=-45).add_to(m)

circles = folium.plugins.pattern.CirclePattern(
    width=20, height=20, radius=5, fill_opacity=0.5, opacity=1
).add_to(m)


def style_function(feature):
    default_style = {
        "opacity": 1.0,
        "fillColor": "#ffff00",
        "color": "black",
        "weight": 2,
    }

    if feature["properties"]["name"] == "Colorado":
        default_style["fillPattern"] = stripes
        default_style["fillOpacity"] = 1.0

    if feature["properties"]["name"] == "Utah":
        default_style["fillPattern"] = circles
        default_style["fillOpacity"] = 1.0

    return default_style

us_states = requests.get(
    "https://raw.githubusercontent.com/python-visualization/folium-example-data/main/us_states.json"
).json()

folium.GeoJson(
    us_states,
    smooth_factor=0.5,
     style_function=style_function,
).add_to(m)

m
```