Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:01,310 --> 00:00:07,680
Hey! Hi again and welcome to this new
lecture! What we have so far is this map
3
00:00:07,680 --> 00:00:13,590
with this 62 markers each of them
representing a volcano location in the
5
00:00:13,590 --> 00:00:20,579
United States, however this map is not
very smart so to say. The only
7
00:00:20,579 --> 00:00:28,949
information that this map conveys is the
locations of the volcanoes and you also
9
00:00:28,949 --> 00:00:33,829
have a base map. There's also a good
aspect of this now because you can
11
00:00:33,829 --> 00:00:39,179
extract information like that if you
click the icons, however you may want to
13
00:00:39,179 --> 00:00:44,850
transform this map to actually show an
attribute instead of just volcano
15
00:00:44,850 --> 00:00:50,789
locations and the way to do that, there may
be different way and that's up to your
17
00:00:50,789 --> 00:00:57,030
knowledge about cartography, but I could
make the map show an attribute here.
19
00:00:57,030 --> 00:01:02,249
For example I could change the colors of
these markers to actually show the
21
00:01:02,249 --> 00:01:09,210
elevation range. Let's say we can
categorize these markers into three
23
00:01:09,210 --> 00:01:16,920
colors, let's say green, orange, and red.
Green would be four elevations from zero
25
00:01:16,920 --> 00:01:23,909
to a 1 000 meter for example or 2 000
meters, and orange would be from 2 000 to
27
00:01:23,909 --> 00:01:30,119
3 000 meters, and then red markers would
represent volcanoes with an
29
00:01:30,119 --> 00:01:37,350
elevation of higher than 3 000 meters.
So how do we do that with Folium? Let's get
31
00:01:37,350 --> 00:01:43,680
back to Atom. Here is our code. What we
have so far? Currently what we're passing
33
00:01:43,680 --> 00:01:51,689
to icon argument is a color argument
with a value of green, so basically what
35
00:01:51,689 --> 00:01:55,369
we need to do we need to make this
dynamic so that the color changes
37
00:01:55,369 --> 00:02:01,079
depending on the elevation.
Unfortunately we cannot do that with
39
00:02:01,079 --> 00:02:06,179
Folium, so folium doesn't have native
functionality to create dynamic colors
41
00:02:06,179 --> 00:02:13,320
for your markers, therefore we need to be
a bit creative here and use Python core
43
00:02:13,320 --> 00:02:17,580
functionalities
to do this, and when you think
45
00:02:17,580 --> 00:02:22,890
about dynamics, I think about
functions so basically this loop is
47
00:02:22,890 --> 00:02:28,799
going through latitude, longitude,
elevation and then it passes those three
49
00:02:28,799 --> 00:02:36,019
values into this expression in here.
However color is being passed as a
51
00:02:36,019 --> 00:02:41,730
a string always, but how do I change it
depending on the elevation for instance?
53
00:02:41,730 --> 00:02:46,459
Well the way to do that is by creating a
function, a function that gets as input
55
00:02:46,459 --> 00:02:53,430
elevation and then it does some actions
inside the function, and then it returns
57
00:02:53,430 --> 00:02:59,099
a color depending on the elevation value.
So you can say if elevation is less than
59
00:02:59,099 --> 00:03:07,829
this give me green color, a green string
here, and so on and so forth. So to give
61
00:03:07,829 --> 00:03:12,540
you an idea the way this would work is,
let me write a function here, this
63
00:03:12,540 --> 00:03:17,609
would be a good place to do that before
creating the map object, but always
65
00:03:17,609 --> 00:03:21,720
always you need to create the function
because I will be calling the function
67
00:03:21,720 --> 00:03:27,599
in here so you need to create the
function before this expression, so from
69
00:03:27,599 --> 00:03:36,290
here and upwards. I'll be creating that
in here. Let's call a function color
71
00:03:36,290 --> 00:03:43,620
producer. Let's keep it simple for a
while just to demonstrate you how this
73
00:03:43,620 --> 00:03:50,730
would work, so let's keep it very very
simple. Let's say return green, and if you
75
00:03:50,730 --> 00:03:59,459
change this to color producer and don't
forget the brackets, by passing brackets
77
00:03:59,459 --> 00:04:04,349
that means you are calling the function.
If you don't pass in the bracket so that
79
00:04:04,349 --> 00:04:08,280
means you're just calling the function
name and you are not executing the
81
00:04:08,280 --> 00:04:17,489
function, so I'll just keep it like that.
And go ahead and execute
83
00:04:17,489 --> 00:04:19,820
map1.py .
All right, reload and you'll get the same
85
00:04:25,300 --> 00:04:33,460
thing, right, because what happens is that
this thing in here this function call
87
00:04:33,460 --> 00:04:41,650
will be equal to whatever you return
here, so the type of this object it's
89
00:04:41,650 --> 00:04:47,440
actually a string so it's exactly the
green string. Therefore now you can add
91
00:04:47,440 --> 00:04:53,169
some conditionals here. Basically you
need to pass an input here, so elevation
93
00:04:53,169 --> 00:05:01,180
let me write whatever variable you like.
I'll write elevation and here you need to pass
95
00:05:01,180 --> 00:05:10,240
el, so el for lat, lon, el. Let's say we
have 62 rows in the data table,
97
00:05:10,240 --> 00:05:15,940
and for loop will go through the first row
of the table, it will get elevation and
99
00:05:15,940 --> 00:05:22,150
it will pass it to this function code, so
the function will pass el into elevation,
101
00:05:22,150 --> 00:05:34,110
and then you say here if elevation is
less than 1 000, then you want to
103
00:05:34,110 --> 00:05:44,860
return green for elevations less than
1000 meters, elif elevation is
105
00:05:44,860 --> 00:05:55,110
between 1 000 meters, so it's
greater than 1 000 meters, or less
107
00:05:55,110 --> 00:06:04,500
then let's say 3 000 meters, return orange,
else return red, so red will be returned
109
00:06:11,710 --> 00:06:17,020
if none of these conditional is
satisfied which means elevation is
111
00:06:17,020 --> 00:06:25,090
neither less than 1 000 meters,
nor between 1 000 and 3 000 meters
113
00:06:25,090 --> 00:06:30,610
which means what is left is
greater than 3 000 meters.
115
00:06:30,610 --> 00:06:34,920
In that case we return red.
For finding out what values actually,
117
00:06:34,920 --> 00:06:40,530
you need to do a little bit of data
exploration, for instance you need to,
119
00:06:40,530 --> 00:06:47,390
you may want to look at the data quickly
like that to see what values you have.
121
00:06:47,390 --> 00:06:56,690
And then decide all the category
thresholds, but you can also make more
123
00:06:56,690 --> 00:07:01,950
significant statistical analysis like
you can make a histogram and see the
125
00:07:01,950 --> 00:07:06,810
data distribution and then decide on
these values, but let's keep things
127
00:07:06,810 --> 00:07:15,270
simple and let's decide on these values.
Okay, I'll save this, check if everything
129
00:07:15,270 --> 00:07:29,820
is in place just quickly, yeah, let me
try the code. Go and reload and yeah, we have
131
00:07:29,820 --> 00:07:38,250
some different colors here, yeah this is
looking good. Let me double check the
133
00:07:38,250 --> 00:07:43,110
values. For instance oranges between
1 000 meters and 3 000 meters
135
00:07:43,110 --> 00:07:50,570
Yeah, we're doing good.
Red is above 3 000 meters.
137
00:07:50,570 --> 00:07:55,000
Yeah, it seems it's working.
8166
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.