I am trying to plot a collection of points onto a graphic of King County, WA.
I can show the graphic with the following code:
fig, ax = plt.subplots(figsize = (15,15))
kings_county.plot(ax=ax)
This gives me the graphic. I then read in the points from the lat/long of a csv I load.
df = pd.read_csv('kc_house_data_train.csv')
crs = {'init': 'epsg:4326'}
And this puts all of the points in a new dataframe
geometry = [Point(x,y) for x,y in zip(df.lat,df.long)]
geo_df = gpd.GeoDataFrame(df, # specifify your dataframe
crs = crs, # this is your coordinate system
geometry = geometry) # specify the geometry list we created
However, when I do this
fig, ax = plt.subplots(figsize = (40,40))
kings_county.plot(ax=ax, alpha = 0.4, color = 'grey', aspect = 'auto')
geo_df[geo_df.price >= 750000].plot(ax = ax , markersize = 20, color = 'blue',marker = 'o',label = 'pricey')
geo_df[geo_df.price < 750000].plot(ax = ax , markersize = 20, color = 'blue',marker = 'o',label = 'pricey')
plt.legend()
It just returns an error: ValueError: 'box_aspect' and 'fig_aspect' must be positive Not sure why loading the graphic works but the added points makes it break.
Just looking for understanding of this and a fix, if you can. Thanks
aspect=1
as a parameter to.plot()
to fix this is wrong and dangerous. It's merely papering over a data problem by suppressing the symptom. If you've confused lat and lon, your results will simply be wrong. – Malarkey