Matplotlib Tutorial 27 - Basemap customization options
Skills:
CV Basics80%
Key Takeaways
This tutorial covers Matplotlib's Basemap extension, focusing on customization options such as map projections, coordinate systems, and visualization parameters, using tools like Matplotlib and Basemap for geographic plotting.
Full Transcript
what's going on everybody welcome to part 27 of our matplotlib tutorial series in this part we're going to continue talking about base map and here we're going to talk about some of the options available to us with base map and their various functions and methods that we can run with it so where we started off in kind of where we left off was with just a simple representation using the Miller projection of our base map graph now or chart or map whatever you want to call it now the next thing that I want us to go ahead and do is talk about some of the more the options that we have so instead of it we're gonna stop I'm gonna stop filling the continents for now but just know you can fill the continents and you can also change the color if you if you want now in the projection we can also add some more some more coordinates and the way that these coordinates are working is let me close out of this old version of paint don't save and we'll open up paint and the way that it coordinates work is you've got you know your entire map might be like this and then you know you've got stuff on the map let's say I'm not gonna attempt to draw the world but let's just assume okay so this is our map and then generally you pick two points you pick the lower left corner point and then you pick the lower or the upper right corner point okay so we're gonna pick that point and for those of you who are not too familiar with maps coordinates are in latitude and longitude longitude goes left to right okay and that's the long kind of left to right longitude and then latitude is the up and down okay so this is your latitude now with latitude and longitude the interesting thing that comes up with plotting in a graph like situation generally coordinates are reported as lat/long so latitude longitude but what is latitude mostly in relation to well latitude is most like the y-axis and longitude is most like the x-axis so at some point with matplotlib we have to flip these around to be to conform to the XY requirement of graphs but you have to understand that they're reported as YX but anyway more on that later but back to the original when we define a coordinate box with base map we defined the lower left and then the upper right the lower left that's the XY coordinate for the lower left point and then the XY for the coordinate up here and then what ends up happening is with these two points we can draw a box that will be our graph so we can draw a box like this right and that's the box that is made up by these coordinates not quite perfect but that's the idea so what we can do is we can minimize this and then we can say so we want to have the Miller projection and then we use a parameter called LLC RN R la T that's lower left corner latitude and let's say the lower left corner latitude will be negative 40 and then lower left corner longitude will also be negative 40 we're gonna we're gonna have this kind of focus in on Africa for us and then oh you are CR n R lat so that's upper right corner lat will be 50 and then the upper right corner long will be 75 okay so our bottom or a lower left point will be negative 40 negative 40 and then our upper right coordinate will be 50 75 so that brings up another point is with latitude and longitude generally what we have is you've got you know your your axes that'll look like this and generally you've got north-south this would be your West and this is your East but in matplotlib you've got basically a plus minus minus plus so all Eastern coordinates are really pluses all Western coordinates are negatives northern coordinates are pluses southern coordinates or negatives okay so this coordinate here negative 40 negative 40 what is that well that latitude is negative 40 that would be south and then you've got negative 40 or I'm sorry that would be 40 South not negative 40 South that would make no sense so 40 South forty West then you've got this 50 would be 50 north and then 75 East basically so let's do so let's go ahead and run this real quick and see what comes up so what we get is Africa with a little bit of outlying Europe and slightly Asia over here but mostly what we're looking at is Africa now there's one more thing that we can show with graphs and that would be the resolution you can do comma resolution and for now we'll do C so the default is C which stands for crude and so when we zoom in let's like zoom in here okay you've got like it's very jaggedy right there's not very much resolution here on the full term scale or even especially like a full map it looks okay like there's a little bit of rounded edges but not really but so that was crude then you have low so that would be L for low and that takes a little longer and you can see actually we get we got a few more rivers we got some islands over here and then again we can zoom into that same Lake and we can see yeah there's definitely a lot more granularity going on there you've got crude low I think H would be high and I believe F is for full we'll have to find out for sure there but I believe F will be our full this one takes a little longer and each step of the way is an 80 percent change so basically yeah you're like almost improving eighty percent I suppose and so anyway here with what we do hi I think we got a lot more detail here and again let's just keep zooming into that same Lake right now you got even more detail here I mean even showing the full lake we really don't see that much jaggedy edges anymore and stuff but then we also again we got way more islands over here that we can actually zoom into and they're like you know zoom way into these islands so there's that and then there's finally f is full let me just try to run that it's gonna take a while to load that one but that is another option that you have so while we're waiting on that I'm gonna go ahead and change this back to will just will do l for low that's pretty quick loading and some of the other things that we're able to do we can also do something like with like the United States we can do something like this we can say let's do this draw coastlines well first of all what we can do is we can do MDOT draw let's do draw countries first countries so we can draw countries that map come up you thank you this is gonna take a while so what this will do is allow us to draw countries but not only do it can we draw countries but we can throw other parameters in here that are like our original matplotlib parameters so an example of this would be like line width and we could say line width equals two okay and I'm gonna run this in last night it's still not up yet I was really hoping to get a full resolution to show you guys but I don't want sit here I don't know how long it's gonna take me to to render the the full one still not there I guess we can just skip it but you can feel free to wait on it yourself if you'd like but yeah it's just not gonna pop up let's just give that for now so now we've got the country definitions here so you can see that we've got like the split of everything and actually what I'll go ahead and do is I'll have us return back let's do negative 90 negative 180 and then here this will be 90 180 so this would be the full world again for us there you go so you can see the country definitions they have a thicker line width right because we chose them to be line width of two but now you've got definition between the United States Canada and then down here like Brazil and Chile and all that I'll split up and then you've got here in Africa and Europe we can see all the divisions now we can close this and that was so draw countries we can have that but another thing we can have is m dot draw states and we can color these and we can have States B let's do now we need something that we can see really well let's do B for blue so save that and run so let's take a little bit longer but yeah so now we've got the States drawn and you should see now that we've separated Australia as well but mainly we were interested in like the United States so we get the States there so those are all separated as you know each of their own another thing that we can do we can even take it in another sector basically and we can do em dot draw counties so now we have the counties of every state and trying to think of a color for these we'll call these dark red see if we can get away with that I've never tried these fancy colors these will take a long time to there's a lot of like little lines for counties but that worked out cool so we can zoom in a little bit here and then we can zoom in to see the counties so now you can see that we've all the counties for the United States all taken care of lol at the amount of counties for Alaska not many people care anyway okay so we've got that there's a couple other things that we can do let's close out of here let's stop drawing I wanted to just show the counties but that takes up a lot of time so I'm going to comment that out and then another thing that we can do is we can add topography so we can say something like this MMD topo and we can add topography to our graph so this will take a little bit to load but it should come up pretty quick and another thing to note with topography and the next one I'm about to show you guys the resolution you draw should should affect these so the higher the resolution the the longer it will take to draw these now we're doing a low I think but yeah so here's your topography so now we've got topography on this graph if that's something you're interested in but we still have the divisions as well so all the country divisions and all the state diff divisions and all that alongside the topography we have so there you go got those but you can see like as you zoom in they're getting kind of like grainy and fuzzy so if you want to you can increase the resolution and that will improve now that was M the topography another one you can do is m dot Blue Marble and this would be the last one I show you before we finish up this specific tutorial and while we wait the next tutorial we're going to cover actually plotting a coordinate so probably the main reason you're gonna graph something with a map is not just to look at a map alright you may care about making the divisions between States and countries and all that but generally you're gonna want to plot something on the map so anyway here's Blue Marble it's kind of like the topography only it's a Blue Marble so you also get you know the oceans in here and also the green versus you know desert and all that and to get a little more information here with the Blue Marble but anyway you choose to do whatever the heck you want to do so anyway I just wanted to show you guys all those kind of options with the graphs that the Blue Marble is the most kind of realistic looking graph and again you can you can take blue marble and you can actually do like a really high resolution but if you're going to do a high resolution you should probably zoom in first and then apply the high resolution rather than have the full graph apply the resolution and then yourself on the graph zoom in and what I mean by zoom in is is modify these coordinates here to be whatever location you're truly interested in rather than rendering everything for all the locations so anyways that's it for this tutorial stay tuned the next tutorial for actually plotting coordinates and stuff like that on the map if you have any questions or comments regarding this tutorial or whatever up to this tutorial please feel free to leave them below otherwise as always thanks for watching things for all the supportive subscriptions and until next time
Original Description
In this Matplotlib tutorial, we continue with the Basemap geographic plotting extension. We're going to show some of the customization options available to us.
sample code: http://pythonprogramming.net
http://hkinsley.com
https://twitter.com/sentdex
http://sentdex.com
http://seaofbtc.com
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from sentdex · sentdex · 0 of 60
← Previous
Next →
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
55
56
57
58
59
60
Matplotlib Python Tutorial Part 1: Basics and your first Graph!
sentdex
Python Encryption Tutorial with PyCrypto
sentdex
Python's Logging Function
sentdex
wxPython Tutorials 1: Making Windows GUIs with Python : Installing + 1st window!
sentdex
wxPython Tutorials 2: Making Windows GUIs with Python: Customizing Window Parameters
sentdex
wxPython Programming Tutorial 3: Menu Bar and Menu Button
sentdex
wxPython Programming Tutorial 4: Panels
sentdex
wxPython Programming Tutorial 5: User Input Saved To Variables
sentdex
wxPython Programming Tutorial 6: Multiple Choice Input
sentdex
wxPython Programming Tutorial 7: Adding Static Text and Colors
sentdex
wxPython Programming Tutorial 8: Custom Button Images
sentdex
wxPython Programming Tutorial 9: Tool Bar Items and Sub Menus!
sentdex
Basic PHP Tutorial 13: Multi-dimensional Array
sentdex
Basic PHP Tutorial 15: Functions and Global Variables
sentdex
Basic PHP Tutorial 12: Associative Array
sentdex
Basic PHP Tutorial 14: Foreach loop
sentdex
Basic PHP Tutorial 16: Include and Require
sentdex
Basic PHP Tutorial 7: Assignment, comparison and Logical operators
sentdex
Basic PHP Tutorial 4: Variables and Comments
sentdex
Basic PHP Tutorial 11: Arrays part 1, basic array
sentdex
Basic PHP Tutorial 6: If else and else if conditionals cont'd
sentdex
Basic PHP Tutorial 1: Intro to PHP
sentdex
Basic PHP Tutorial 3: HTML with PHP
sentdex
Basic PHP Tutorial 9: While Loop
sentdex
Basic PHP Tutorial 10: Switch Statement
sentdex
Basic PHP Tutorial 2: Print and Echo
sentdex
Basic PHP Tutorial 5: If else and else if conditional statements
sentdex
Basic PHP Tutorial 8: Arithmatic Operators: Doing math with php
sentdex
Basic PHP Tutorial 17: User Input Form Example / String Manipulation
sentdex
Basic PHP Tutorial 18: HTML Entities and forms cont'd
sentdex
Basic PHP Tutorial 19: Finding words in strings
sentdex
Basic PHP Programming Tutorial 20: Saving to a File / writing and appending
sentdex
Basic PHP Programming Tutorial 22: Hashing part 2: salting
sentdex
Basic PHP Programming Tutorial 23: Variables in Strings and tokenizing
sentdex
Basic PHP Programming Tutorial 21: MD5 Hashing For Security
sentdex
Basic PHP Programming Tutorial 24: String similarity
sentdex
Basic PHP Programming Tutorial 25: Time and Time stamps
sentdex
Basic PHP Programming Tutorial 26: Die and Exit
sentdex
Basic PHP Programming Tutorial 27: MySQL Databases Part 1
sentdex
Basic PHP Programming Tutorial 28: MySQL Database Part 2: Reading From Database
sentdex
Basic PHP Programming Tutorial 29: MySQL Database Part 3: Inputting Data
sentdex
Basic PHP Programming Tutorial 30: MySQL database in Use
sentdex
Django Tutorial Web Development with Python Part 1: Installing Django
sentdex
Python Tutorial: File Deletion and Folder Deletion / directory deletion
sentdex
Python Tutorial: How to Rename Files and Move Files with Python
sentdex
3D Graphs in Matplotlib for Python: Basic 3D Line
sentdex
3D Plotting in Matplotlib for Python: 3D Scatter Plot
sentdex
3D Charts in Matplotlib for Python: Multiple datasets scatter plot
sentdex
Sikuli Tutorial 1: Visually programming in python!
sentdex
Sikuli Tutorial 2: Program visually in python!
sentdex
Sikuli Tutorial 3: Program visually in python!
sentdex
3D Bar Charts in Python and Matplotlib
sentdex
3D Plane wire frame Graph Chart in Python
sentdex
Raspberry Pi Part 1 Introduction
sentdex
Raspberry Pi Part 8: First Download and Update! (Firmware)
sentdex
Raspberry Pi Part 10: How to set up a Linux Web Server on your Pi
sentdex
Raspberry Pi Part 11: Remote Desktop
sentdex
Twitter Analysis: How to rank a user's influence
sentdex
GPIO Tutorial for Pi Part 2 - Programming the GPIO
sentdex
GPIO Tutorial for Raspberry Pi Part 1 - Setting up
sentdex
More on: CV Basics
View skill →
🎓
Tutor Explanation
DeepCamp AI