Monday, April 10, 2017

Voting Districts Day 10: Creating a basic map with Matplotlib

Last time, we converted our coordinates from the weird NC format to the standard lat/long format in anticipation of matplotlib needing a better format. 

This time, we are just trying to create something very basic.  I would love to just see a picture with North Carolina on it, for instance.  

So, the package that we need to do this from matplotlib is: 
from mpl_toolkits.basemap import Basemap

To create a basemap, use the following command:
m = Basemap(projection= 'cyl', lon_0 = -80, lat_0 = 35, llcrnrlon=-84.9,llcrnrlat=33.5,urcrnrlon=-75.,urcrnrlat=36.6, resolution='i')

There are a lot of properties in here.  lon_0 and lat_0 set the center point of the map.  llcrnrlon (left lower corner longitude), llcrnrlat (lower left latitude), urcrnrlon (upper right longitude), and rucrnrlat (upper right latitude) set the corner points of the map.  resolution seems pretty general.  h is really a high resolution, but i seems to be adequate for me.  Finally, projection appears to be the type of map.  cyl is the default value and, according to the matplotlib documentation, it seems to be the easiest to get along with.  I'm probably going to need that to deal with the custom North Carolina projections.  All the properties can be found here.

You can also add standard map stuff to your basemap, like coastline boundaries, state/ county/ country boundaries.  I want the coastlines and an outline of the state.

To plot my results, I'm going to need matplotlib pyplot package.  

Putting it all together...
from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
m = Basemap(projection= 'cyl', lon_0 = -80, lat_0 = 35, llcrnrlon=-84.9,llcrnrlat=33.5,urcrnrlon=-75.,urcrnrlat=36.6, resolution='i')
m.drawstates(linewidth=0.5)
m.drawcoastlines(linewidth=0.5)

#save a picture of our map.
plt.savefig('basic_map.png',dpi=300)

And here's what we get!  We still need a little tweaking, but not too terrible.



1 comment:

terry james said...

I'm very excited to inform everyone that I'm completely cured from my HSV 1&2 recently. I have used Oregano oil, Coconut oil, Acyclovir, Val acyclovir, Famciclovir , and some other products and it's really help during my outbreaks but I totally got cured from my HSV 2 with a strong and active herbal medicine ordered from a powerful herbalist and it completely fought the virus from my nervous system and I was tested negative after three weeks of usage. I'm here to let y'all know that HSV 1& 2 has a complete cure, I got rid of mine with the help of Dr Moses Buba and his herbal exploit, AFTER I engage with other wrong doctors. Contact him via email: buba.herbalmiraclemedicine@gmail.com or Call/WhatsApp him at +2349060529305
thank you..








I'm very excited to inform everyone that I'm completely cured from my HSV 1&2 recently. I have used Oregano oil, Coconut oil, Acyclovir, Val acyclovir, Famciclovir , and some other products and it's really help during my outbreaks but I totally got cured from my HSV 2 with a strong and active herbal medicine ordered from a powerful herbalist and it completely fought the virus from my nervous system and I was tested negative after three weeks of usage. I'm here to let y'all know that HSV 1& 2 has a complete cure, I got rid of mine with the help of Dr Moses Buba and his herbal exploit, AFTER I engage with other wrong doctors. Contact him via email: buba.herbalmiraclemedicine@gmail.com or Call/WhatsApp him at +2349060529305
thank you..










I'm very excited to inform everyone that I'm completely cured from my HSV 1&2 recently. I have used Oregano oil, Coconut oil, Acyclovir, Val acyclovir, Famciclovir , and some other products and it's really help during my outbreaks but I totally got cured from my HSV 2 with a strong and active herbal medicine ordered from a powerful herbalist and it completely fought the virus from my nervous system and I was tested negative after three weeks of usage. I'm here to let y'all know that HSV 1& 2 has a complete cure, I got rid of mine with the help of Dr Moses Buba and his herbal exploit, AFTER I engage with other wrong doctors. Contact him via email: buba.herbalmiraclemedicine@gmail.com or Call/WhatsApp him at +2349060529305
thank you..