1 of 12

CSE 163

Geopandas�

Suh Young Choi

🎶 Listening to: Unwed Sailor

💬 Make sure to join the Slido!�🪶 Question of the Day: Do you have a favorite flag?

Or go to slido.com and enter:

#1174074

2 of 12

Announcements

Project proposals due Wednesday (May 14)

    • See Canvas assignment for more details
    • See Ed post #338 if you’re looking for partners

Education Interview grades released

Search grades released later tonight ☺

Education resubmissions close on Thursday (May 15)

2

3 of 12

This Time

  • Geospatial data
  • Using Geopandas

Last Time

  • Data Settings
  • Object-Oriented Programming
  • Classes

3

4 of 12

Geospatial Data

  • Simply put, maps!
  • Represents places in the world and accompanying data

4

5 of 12

Geopandas

  • Exactly like pandas, but with an extra geometry column
  • Files typically end in .shp
  • Can be used for plotting
  • Types
    • GeoDataFrame
    • GeoSeries

5

6 of 12

Geopandas

  • Exactly like pandas, but with an extra geometry column
  • Files typically end in .shp
  • Can be used for plotting
  • Types
    • GeoDataFrame
    • GeoSeries

6

import geopandas as gpd

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

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

plt.savefig('plot.png')

7 of 12

Matplotlib

  • 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) # nrows, ncols

<plot1>(ax=ax1)

<plot2>(ax=ax2)

fig.savefig('plot_separate.png')

8 of 12

Matplotlib

8

fig

ax1

ax2

fig, [ax1, ax2] = plt.subplots(1, 2) # nrows, ncols

<plot1>(ax=ax1)

<plot2>(ax=ax2)

fig.savefig('plot_separate.png')

9 of 12

Matplotlib

9

fig

ax1

ax2

fig, [ax1, ax2] = plt.subplots(1, 2) # nrows, ncols

<plot1>(ax=ax1)

<plot2>(ax=ax2)

fig.savefig('plot_separate.png')

10 of 12

Matplotlib

10

fig

ax1

ax2

fig, [ax1, ax2] = plt.subplots(1, 2) # nrows, ncols

<plot1>(ax=ax1)

<plot2>(ax=ax2)

fig.savefig('plot_separate.png')

11 of 12

Jupyter time!

11

12 of 12

Before Next Time

  • Work on Project Proposals

Next Time

  • Two special Geopandas functions

12