Reputation: 377
Now this part of code gives me figures for each cells on each map region, even on these which has no data at all. How to show it only for regions which has values in initial table?
import matplotlib as mpl
import matplotlib.pyplot as plt
import geopandas as gpd
import pandas as pd
...
variable = 'price'
vmin, vmax = 10,90
fig=plt.figure(figsize=(12,12))
axK = fig.add_subplot(2,2,1)
mergedK.plot(column=variable, cmap='Blues',
vmin=vmin,
vmax=vmax,
linewidth=0.8, ax=axK, edgecolor='0.8')
for _,region in mergedK.iterrows():
axK.annotate(region['price'],
xy=(region.geometry.centroid.x,
region.geometry.centroid.y),fontsize=8)
plt.show()
Upvotes: 0
Views: 784
Reputation: 7814
The latest GeoPandas (0.7.0) handles missing value automatically. The easiest way for you is to update. By default missing values are not shown on a map, but you can specify style kwargs to show them in a way you like. See the documentation for more details.
To skip the annotation for missing value, just add this condition to your loop:
for _,region in mergedK.iterrows():
if pd.notna(region['price']):
axK.annotate(region['price'],
xy=(region.geometry.centroid.x,
region.geometry.centroid.y),fontsize=8)
Upvotes: 1