1 of 13

CSE 163

Geopandas�

Suh Young Choi

2 of 13

Announcements

Midterm evaluations have opened!

  • Will be open until end of today (7/28)
  • If >60% of the class fills it out, everyone gets an extra day on HW4!
  • Feedback also helps us out a ton!!

​

Checkpoint 2 + LR 4 due tonight

​

HW4 due this Thursday (unless… 👀)

2

3 of 13

This Time

  • Geospatial data
  • Using Geopandas

Last Time

  • Magic methods
  • os
  • HW4 concepts

3

4 of 13

Geopandas

  • Exactly like pandas, but with some extra features for geo data
  • Types
    • GeoDataFrame
    • GeoSeries

​

​

​

​

4

import geopandas as gpd

​

df = gpd.read_file('data_file.shp')

​

df.plot(column='some_col', legend=True)

plt.savefig('plot.png')

​

5 of 13

zip

  • zip is a helpful built-in function to help you combine lists

​

  • Note: zip does not return a list! It returns a generator
    • Can only access the values by iterating over them
    • Can only be used once! Iterating “consumes” the series

​

​

​

5

x = [1,2,3]

y = [4,5,6]

zip(x, y)

​

​

6 of 13

Matplotlib

  • Before, we were using a lot of matplotlib stuff blindly
  • Default plots gets plotted on a global figure (think canvas)
    • Multiple plots would overwrite each other
  • You have to do extra work to get more information on the same set of axes.

​

6

fig, ax = plt.subplots(1)

<plot1>(ax=ax)

<plot2>(ax=ax)

fig.savefig('plot_together.png')

​

​

​

​

​

7 of 13

Matplotlib

  • Before, we were using a lot of matplotlib stuff blindly
  • Default plots gets plotted on a global figure (like a canvas)
    • Multiple plots would overwrite each other
  • You have to do extra work to get more information on the same set of axes.

​

7

fig, ax = plt.subplots()

<plot1>(ax=ax)

<plot2>(ax=ax)

fig.savefig('plot_together.png')

​

​

​

​

​

fig, [ax1, ax2] = plt.subplots(1, 2) # width, height

<plot1>(ax=ax1)

<plot2>(ax=ax2)

fig.savefig('plot_separate.png')

​

​

​

​

​

8 of 13

Matplotlib

  • Before, we were using a lot of matplotlib stuff blindly
  • Default plots gets plotted on a global figure (like a canvas)
    • Multiple plots would overwrite each other
  • You have to do extra work to get more information on the same set of axes.

​

8

fig

ax1

ax2

9 of 13

Matplotlib

  • Before, we were using a lot of matplotlib stuff blindly
  • Default plots gets plotted on a global figure (like a canvas)
    • Multiple plots would overwrite each other
  • You have to do extra work to get more information on the same set of axes.

​

9

fig

ax1

ax2

10 of 13

Matplotlib

  • Before, we were using a lot of matplotlib stuff blindly
  • Default plots gets plotted on a global figure (like a canvas)
    • Multiple plots would overwrite each other
  • You have to do extra work to get more information on the same set of axes.

​

10

fig

ax1

ax2

11 of 13

Hurricane Florence

11

12 of 13

Hurricane Florence

12

13 of 13

Before Next Time

  • Complete Lesson 16
    • Remember not for points, but do go towards Checkpoint Tokens
  • CP2 + LR 4 due tonight
  • Fill out the midterm evals!
  • Resub cycle closes tomorrow (last day to resubmit HW1)

​

Next Time

  • Two special Geopandas functions

​

13