0

With this code i'm plotting values of a map:

conditions = [(maxcwd1['CWD'] == 0),
    (maxcwd1['CWD'] > 0) & (maxcwd1['CWD'] < 3),
    (maxcwd1['CWD'] >= 3) & (maxcwd1['CWD'] < 5),
    (maxcwd1['CWD'] >= 5) & (maxcwd1['CWD'] < 7),
    (maxcwd1['CWD'] >= 7) & (maxcwd1['CWD'] < 10),
    (maxcwd1['CWD'] >= 10) & (maxcwd1['CWD'] < 15),
    (maxcwd1['CWD'] >= 15) & (maxcwd1['CWD'] < 20),
    (maxcwd1['CWD'] >= 20) & (maxcwd1['CWD'] <= 31)
]

sizes = [100,200,300,400,500,600,700,800]
maxcwd1['size'] = np.select(conditions, sizes)

#______________________________________________________________________________
fig = plt.figure('map', figsize=(20,25), dpi=300)
ax = fig.add_axes([0.05, 0.05, 0.90, 0.85], projection=ccrs.PlateCarree())
l1 = NaturalEarthFeature(category='cultural', name='admin_0_countries', scale='50m', facecolor='none')

ax.add_feature(cfeature.OCEAN.with_scale('50m'), facecolor='deepskyblue')
ax.add_feature(cfeature.LAND.with_scale('50m'))
ax.add_feature(cfeature.COASTLINE.with_scale('50m'))
ax.add_feature(COUNTIES, edgecolor='black',linewidth=0.5,facecolor='#BDBBC4',zorder=2)
ax.add_feature(COUNTIES_P, edgecolor='black',linewidth=0.5,facecolor='#E1E1E1',zorder=2)

for index, row in maxcwd1.iterrows():
    ax.scatter(row['Longitud'], row['Latitud'], s=row['size'], color='black',
    marker='o',edgecolors="black",linewidth=1,zorder=4,transform=ccrs.PlateCarree())

#And the legend:

m6 = mlines.Line2D([], [], color='black', marker='o', linestyle='None',markeredgecolor='black',
                      markersize=5, label='0')
m7 = mlines.Line2D([], [], color='black', marker='o', linestyle='None',markeredgecolor='black',
                      markersize=10, label='[1-3>')
m8 = mlines.Line2D([], [], color='black', marker='o', linestyle='None',markeredgecolor='black',
                          markersize=15, label='[3-5>')
m9 = mlines.Line2D([], [], color='black', marker='o', linestyle='None',markeredgecolor='black',
                          markersize=20, label='[5-7>')
m10 = mlines.Line2D([], [], color='black', marker='o', linestyle='None',markeredgecolor='black',
                          markersize=25, label='[7-10>')
m11 = mlines.Line2D([], [], color='black', marker='o', linestyle='None',markeredgecolor='black',
                          markersize=30, label='[10-15>')
m12 = mlines.Line2D([], [], color='black', marker='o', linestyle='None',markeredgecolor='black',
                          markersize=35, label='[15-20>')
m13 = mlines.Line2D([], [], color='black', marker='o', linestyle='None',markeredgecolor='black',
                          markersize=40, label='[20-31]')

leg=ax.legend(handles=[m6, m7,m8,m9,m10,m11,m12,m13],title='CWD',title_fontsize=20,
         fontsize=22, bbox_to_anchor=(0.04, 0.22, 0.1, 0.35),
         borderpad=0.45, labelspacing=0.75,handlelength=0.4, facecolor='white',edgecolor='black',borderaxespad=0.004)

The problem is when I try to put the same sizes of the markers in the legend and in the ax.scatter. They are not the same size on the legend as on the map. They come out exaggeratedly bigger.

How can i solve this?

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
Javier
  • 493
  • 3
  • 15

0 Answers0