I am plotting a gpd map with an overlay of scatterplot and circle patches. However, when I run the code, the output only displays the scatterplot and circle patches without the border maps. There is nothing wrong with the map as I tried running it separately and it is showing the right output. Please see the image description below for how the plot looks like.
Here is the code:
def plot_dbscan(points, dbscan, title, pt_sizer=1, plot_circles=False):
# Index noise and clusters out of the dbscan points
noise = points[dbscan.labels_ == -1]
clusters = points[dbscan.labels_ != -1]
# Plot country border
fig, ax = plt.subplots(1, figsize=(12,8))
map_1_prj.plot(ax=ax, fc='None', ec='k', linewidth=1.5)
# Allow relative point size adjustment with pt_sizer argument
sns.scatterplot(x=noise[:,0], y=noise[:,1], ax=ax, alpha=1, s=2*pt_sizer, color='gray')
sns.scatterplot(x=clusters[:,0], y=clusters[:,1], ax=ax, s=4*pt_sizer, color='red')
# Option to plot a minimum bounding circle around each cluster
if plot_circles:
for label in np.unique(dbscan.labels_):
if label != -1:
cluster_points = points[dbscan.labels_ == label]
# Get minimum bounding circle using pointpats.centrography.minimum_bounding_circle()
(center_x, center_y), radius = minimum_bounding_circle(cluster_points)
# Create matplotlib patch
circle_patch = mpatches.Circle((center_x, center_y), radius=radius, fc='None', ec='yellow', linewidth=2)
ax.add_patch(circle_patch)
ax.axis('equal')
# Limit bounds of plot to earthquake data
ax.set_xlim(gdf_prj.total_bounds[0], gdf_prj.total_bounds[2])
ax.set_ylim(gdf_prj.total_bounds[1], gdf_prj.total_bounds[3])
# Manually prepare legend items
Ph_border = mlines.Line2D([], [], color='k', linewidth=1.5, label='Philippine Border')
noise_l = mlines.Line2D([], [], marker='.', linewidth=0, markersize=4,
color='gray', label='Noise')
if plot_circles:
# Draw yellow circle around red point for legend
mec = 'yellow'
else:
mec = 'None'
clusters_l = mlines.Line2D([], [], marker='.', linewidth=0,
markersize=12, color='red', markeredgecolor=mec,
label='DBSCAN Clusters')
# Define legend
plt.legend(handles=[Ph_border, noise_l, clusters_l])
plt.title(title)
plt.show()