Skip to content

Course Notes

Use this workspace to take notes, store code snippets, and build your own interactive cheatsheet!

Note that the data from the course is not yet added to this workspace. You will need to navigate to the course overview page, download any data you wish to use, and add it to the file browser.

# Import any packages you want to use here
import matplotlib.pyplot as plt

Take Notes

Add your code snippets here Import matplotlib.pyplot import matplotlib.pyplot as plt

##Scatterplot 1 - father heights vs. son heights with darkred square markers

plt.scatter(father_son.fheight, father_son.sheight, c = 'darkred', marker = 's')

##Show your plot plt.show()

Add your notes here

Import matplotlib.pyplot

import matplotlib.pyplot as plt

Scatterplot 2 - yellow markers with darkblue borders

plt.scatter(father_son.fheight, father_son.sheight, c = 'yellow', edgecolor = 'darkblue')

Show the plot

plt.show()

Import matplotlib.pyplot

import matplotlib.pyplot as plt

Scatterplot 3

plt.scatter(father_son.fheight, father_son.sheight, c = 'yellow', edgecolor = 'darkblue') plt.grid() plt.xlabel('father height (inches)') plt.ylabel('son height (inches)') plt.title('Son Height as a Function of Father Height')

Show your plot

plt.show()

A DataFrame named df has been pre-loaded for you. Complete the code to extract longitude and latitude to new, separate columns.

print the first few rows of df

print(df.head())

extract latitude to a new column: lat

df['lat'] = [loc[0] for loc in df.Location]

extract longitude to a new column: lng

df['lng'] = [loc[1] for loc in df.Location]

print the first few rows of df again

print(df.head())

Import pandas and matplotlib.pyplot using their customary aliases

import pandas as pd import matplotlib.pyplot as plt

Load the dataset

chickens = pd.read_csv(chickens_path)

Look at the first few rows of the chickens DataFrame

print(chickens.head())

Plot the locations of all Nashville chicken permits

plt.scatter(x = chickens.lng, y = chickens.lat) (x = долгота, y = широта)

Show the plot

plt.show()

Geometries and shapefiles

Import geopandas

import geopandas as gpd

Read in the services district shapefile and look at the first few rows.

service_district = gpd.read_file(shapefile_path) print(service_district.head())

Print the contents of the service districts geometry in the first row

print(service_district.loc[0, 'geometry'])

Import packages

import geopandas as gpd import matplotlib.pyplot as plt

Plot the Service Districts without any additional arguments

service_district.plot() plt.show()

Plot the Service Districts, color them according to name, and show a legend

service_district.plot(column = 'name', legend = True) plt.show()

Plot the service district shapefile

service_district.plot(column='name', legend=True)

Add the chicken locations

plt.scatter(x=chickens.lng, y=chickens.lat, c='black', edgecolor = 'white')

Add labels and title

plt.title('Nashville Chicken Permits') plt.xlabel('longitude') plt.ylabel('latitude')

Add grid lines and show the plot

plt.grid() plt.show()

Creating and joining GeoDataFrames

GeoJSON and plotting with geopandas

Set legend style

lgnd_kwds = {'title': 'School Districts', 'loc': 'upper left', 'bbox_to_anchor': (1, 1.03), 'ncol': 1}

Plot the school districts using the summer colormap (sequential)

school_districts.plot(column = 'district', cmap = 'summer', legend = True, legend_kwds = lgnd_kwds) plt.xlabel('Longitude') plt.ylabel('Latitude') plt.title('Nashville School Districts') plt.show();

Set legend style

lgnd_kwds = {'title': 'School Districts', 'loc': 'upper left', 'bbox_to_anchor': (1, 1.03), 'ncol': 1}

Plot the school districts using Set3 colormap without the column argument

school_districts.plot(cmap = 'Set3', legend = True, legend_kwds = lgnd_kwds) plt.xlabel('Longitude') plt.ylabel('Latitude') plt.title('Nashville School Districts') plt.show();