# How to "Make a map that shows safety scores by district" (in: Guided Project: Analyzing NYC High School Data)

On the second step of this course the program asks:

Map out safety scores.

• Compute the average safety score for each district.
• Make a map that shows safety scores by district.

Calculating the average is straightforward:

``````school_dist = combined.groupby("school_dist").agg(numpy.mean)
``````

And we also get the lat and lon to display it.

But how do I draw a map where these averages are shown instead of the dot as normally the scatterplot would do?

Thanks

1 Like

``````from mpl_toolkits.basemap import Basemap

longitudes = districts_safety["lon"].tolist()
latitudes = districts_safety["lat"].tolist()

m = Basemap(
projection='merc',
llcrnrlat=40.496044,
urcrnrlat=40.915256,
llcrnrlon=-74.255735,
urcrnrlon=-73.700272,
resolution='i'
)

m.drawmapboundary(fill_color='#85A6D9')
m.drawcoastlines(color='#6D5F47', linewidth=.4)
m.drawrivers(color='#6D5F47', linewidth=.4)

m.scatter(longitudes,latitudes,s=50,zorder=2,latlon=True,c=districts_safety["saf_s_11"],cmap="summer")
plt.title("District Safety Perception")
plt.colorbar()
plt.show()
``````
3 Likes

Thanks for this, I also found this helpful.

This is perhaps a new question but related so I will post here, it is to do with the size of the plot.
I have had a terrible time trying to just increase the size of the plot.

I have been looking at documentation : https://matplotlib.org/3.1.0/api/_as_gen/matplotlib.pyplot.figure.html

And trying all sorts of settings…

``````plt.figure(figsize=(5,5))
``````

etc…

Any help out there on how to adjust the size of the map?

I can’t thank you enough for this! Have been stuck for some time now.

1 Like