Hello everyone and welcome to the Karplus maps exercises solution's lecture in this lecture.
We're going to be coding up solutions for the exercises on the Karplus maps section.
Let's go ahead and chump's that you put a notebook to get started.
All right.
Here I am at the Jupiter notebook.
I want to go ahead and run the plotline imports despite running shift enter there and then the first
thing we want to do is import pandas as PD and then we're going to go ahead and use pandas to read the
CXXVI 2014 underscore world power consumption.
So I'm going to go and say the sequel to PD read CXXVI and then passen 2014.
Or I can actually just use to find fine and complete this and let's go ahead and check the head of the
data frame the head.
And here we have it.
OK.
Now we want to reference electional to create a core plot of the power consumption for countries using
the data and layout dictionary.
Let's go ahead and start off with the data dictionary.
When they call the casting dictionary and then I'm going to say tie is equal to chloroplast as we've
done before.
The next key I'm going to go an answer is locations and that's going to go ahead and be equal to the
column of the location codes.
In this case it's just country here.
So I'm just going to pass in a country
and then I'm going to say location mode and here's where you had a reference that documentation to figure
out the location mode is country space names.
And there's a full length to the documentation right here.
You can go ahead and click that link.
It'll take you to the full documentation reference and you can look up what is the correct location
mode for the specific country.
Since we don't actually have the country codes in this case we have the country names and hopefully
by looking up in the documentation you are able to discover that or just by referencing these solutions
.
Next up we want to specify z and z is going to be equal to the if and we want it to be the power consumption
column.
That's what we actually want our coloring to represent.
So you can go ahead and say power consumption and it's going to be let's say W H there and then the
text is going to go ahead and have that the the country name as well.
So going on to say text is country and then finally we'll label our color bar to be the dictionary or
a title and the color bar label is just going to be or the title color bar going to be power consumption
KWH.
Right.
And that's our basic data dictionary we're going to come back to it and add a couple more arguments
later on.
But then let's also do our layouts.
So I'm going to say lay out a dictionary.
So the title of this to be just the title of the plot will go on and say 2014 power consumption as the
title.
And then next screen you set up a geo key and then pasan a dictionary call say show frame a sequel to
false and then say projection.
And you can pass in any projection you want as was shown in the earlier lectures.
But let's just go ahead and stick with this.
For direction.
And now let's go ahead and run the lasso and see what we get up.
All right.
And here you can see the 2014 power consumption of the world and we can see that China and USA have
the highest power consumption now and the solution is NOT book.
I went ahead and changed the color scale by saying as an argument in the data dictionary I said color
scale is equal to this.
And then I also said reverse scale is equal to true.
And that just makes this color scale a little nicer.
You don't have to do this is kind of optional but I prefer the sort of color scale it makes a little
more obvious between the countries instead of having them all grayed out.
All right.
That was the way it's make the 2014 power consumption plot.
And again a lot of this was having to look stuff up in the documentation which I know can be tricky
and annoying at times but for such strange syntax choices as far as plotting the stuff out you're really
going to have to do that when you want to create these plots.
It's going to be difficult to try to call these things directly from your memory.
All right now go ahead and move on to the USA choral clef.
We want to do is import the 2012 election data.
I'm going to go out and use panelist to do that.
I'll say USDA is equal to PD.
Read CXXVI and then we're going to look at the 2012 election data.
I mean just using tab to autocomplete that.
And then I'm going to just check the head of that data frame by saying us the Fed.
And here we get the matching data frame.
Now let's go in and create a plot that displays the voting age population per state.
The AP going to make my data dictionary by saying data equals dicks and then all say type is Curle plus
.
And let's go ahead and add in those color scale arguments so I'll go in and say a color scale is equal
to this and also a reverse scale to be true.
And the reason I say reverse scale equal to true is so that it actually reverses the color scale.
Let me go to show you just real quick what happens if we don't put that in by say reverse scale let's
say equals false here which is the default.
Then I get a scale that looks like this which isn't really as nice as having the reverse so you can
reverse any color scale you want just by adding in that parameter.
And for this it usually works much better if you actually say reverse scale is true.
So this is what it looks like by default so not reversed but I prefer the darker colors to be the higher
quantity.
That way it's a little more clear.
All right.
Continuing on if we jump back here we'll go out and say reverse scale's equals true locations.
It's going to be equal to the state abbreviation which if we actually look at this here we have both
the state name and the state abbreviation at the end.
Let's go ahead use state abbreviation we'll say USCF Hassen the state's abbreviation column.
Next we want to choose or Z and this was already told to you what you should choose.
It was the voting age population.
The AP and then location mode.
It's going to be called two.
Just like in the examples USA states just like in the lecture and then our text.
Let's go ahead and just choose the text to be the actual state name so USCF States and then we're going
to go ahead and do it say color bar
is equal to and then we pass in a dictionary here.
Title and this is going to just be voting age population.
Let's run that.
All right we have a data dictionary.
Now it's time to make our lay out dictionary.
We pass in our casting dictionary.
We set the title of our entire plot here we'll just call it 2012 election data.
You can call it whatever you want.
We'll say Geo's equal to dictionary.
Cisco USA.
Another argument we're going to say is show Lakes equals true.
And then we just choose the lake color and I want to do the late color with the RSGB mechanism we saw
in the lectures where partly accepts a string.
It's kind of in a strange format these say R.G. B.
And then you actually pass in the numerical values and choose these numbers 85 173 and 240 which gets
us a nice blue hue for the Lakes.
All right.
That's our lay out.
Let's going to run this.
And here we see 2012 election data and it makes sense that the most populous states such as California
Texas and New York and Florida have the darker colors because they have the highest population meaning
they have probably also the highest voting age population.
All right.
That's it for the coral maps exercises.
It was just this USA election data and this international power consumption data hopefully has seen
the power of plotline in being able to reproduce the sort of pretty advanced plots.
And with just a few lines of code that comes at the cost of the syntax being a little strange and having
to reference documentation but having a plot that looks this nice and being able to interact with it
and zoom in and check up the numbers and set text to what you want for having hover over it's pretty
nice.
Given how much code you're actually writing in other languages this would take much much more code.
All right.
Hope you enjoy those core Pluff maps exercises they are meant to be very challenging and having to reference
a lot of the documentation in order to fully understand it.
But that's also kind of just a real world example of what you can do when doing these things on your
own.
But you enjoyed it.
Thanks everyone and I'll see you at the next lecture