Afrikaans
Akan
Albanian
Amharic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
English
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
French
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Hungarian
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranรฎ)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Persian
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Russian
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
1
Hey! Hi again and welcome to this new
lecture! What we have so far is this map
3
with this 62 markers each of them
representing a volcano location in the
5
United States, however this map is not
very smart so to say. The only
7
information that this map conveys is the
locations of the volcanoes and you also
9
have a base map. There's also a good
aspect of this now because you can
11
extract information like that if you
click the icons, however you may want to
13
transform this map to actually show an
attribute instead of just volcano
15
locations and the way to do that, there may
be different way and that's up to your
17
knowledge about cartography, but I could
make the map show an attribute here.
19
For example I could change the colors of
these markers to actually show the
21
elevation range. Let's say we can
categorize these markers into three
23
colors, let's say green, orange, and red.
Green would be four elevations from zero
25
to a 1 000 meter for example or 2 000
meters, and orange would be from 2 000 to
27
3 000 meters, and then red markers would
represent volcanoes with an
29
elevation of higher than 3 000 meters.
So how do we do that with Folium? Let's get
31
back to Atom. Here is our code. What we
have so far? Currently what we're passing
33
to icon argument is a color argument
with a value of green, so basically what
35
we need to do we need to make this
dynamic so that the color changes
37
depending on the elevation.
Unfortunately we cannot do that with
39
Folium, so folium doesn't have native
functionality to create dynamic colors
41
for your markers, therefore we need to be
a bit creative here and use Python core
43
functionalities
to do this, and when you think
45
about dynamics, I think about
functions so basically this loop is
47
going through latitude, longitude,
elevation and then it passes those three
49
values into this expression in here.
However color is being passed as a
51
a string always, but how do I change it
depending on the elevation for instance?
53
Well the way to do that is by creating a
function, a function that gets as input
55
elevation and then it does some actions
inside the function, and then it returns
57
a color depending on the elevation value.
So you can say if elevation is less than
59
this give me green color, a green string
here, and so on and so forth. So to give
61
you an idea the way this would work is,
let me write a function here, this
63
would be a good place to do that before
creating the map object, but always
65
always you need to create the function
because I will be calling the function
67
in here so you need to create the
function before this expression, so from
69
here and upwards. I'll be creating that
in here. Let's call a function color
71
producer. Let's keep it simple for a
while just to demonstrate you how this
73
would work, so let's keep it very very
simple. Let's say return green, and if you
75
change this to color producer and don't
forget the brackets, by passing brackets
77
that means you are calling the function.
If you don't pass in the bracket so that
79
means you're just calling the function
name and you are not executing the
81
function, so I'll just keep it like that.
And go ahead and execute
83
map1.py .
All right, reload and you'll get the same
85
thing, right, because what happens is that
this thing in here this function call
87
will be equal to whatever you return
here, so the type of this object it's
89
actually a string so it's exactly the
green string. Therefore now you can add
91
some conditionals here. Basically you
need to pass an input here, so elevation
93
let me write whatever variable you like.
I'll write elevation and here you need to pass
95
el, so el for lat, lon, el. Let's say we
have 62 rows in the data table,
97
and for loop will go through the first row
of the table, it will get elevation and
99
it will pass it to this function code, so
the function will pass el into elevation,
101
and then you say here if elevation is
less than 1 000, then you want to
103
return green for elevations less than
1000 meters, elif elevation is
105
between 1 000 meters, so it's
greater than 1 000 meters, or less
107
then let's say 3 000 meters, return orange,
else return red, so red will be returned
109
if none of these conditional is
satisfied which means elevation is
111
neither less than 1 000 meters,
nor between 1 000 and 3 000 meters
113
which means what is left is
greater than 3 000 meters.
115
In that case we return red.
For finding out what values actually,
117
you need to do a little bit of data
exploration, for instance you need to,
119
you may want to look at the data quickly
like that to see what values you have.
121
And then decide all the category
thresholds, but you can also make more
123
significant statistical analysis like
you can make a histogram and see the
125
data distribution and then decide on
these values, but let's keep things
127
simple and let's decide on these values.
Okay, I'll save this, check if everything
129
is in place just quickly, yeah, let me
try the code. Go and reload and yeah, we have
131
some different colors here, yeah this is
looking good. Let me double check the
133
values. For instance oranges between
1 000 meters and 3 000 meters
135
Yeah, we're doing good.
Red is above 3 000 meters.
137
Yeah, it seems it's working.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.