0

I am trying to label each point on this scatter plot with its name. So far - all my annotations end up in the bottom left corner. the plot How can I label each point? I see that other question that is similar but that is the question I used to create this code that isn't working... I not very good with for loops. I am not sure I set this one up correctly and if so, why won't it get the well names from my df and plot them based on their lat/lon?

this is the code I have:

   from mpl_toolkits.basemap import Basemap

   f, ax = plt.subplots(1,1,figsize=(20,20))

   m = Basemap(llcrnrlon = 2.4,llcrnrlat =60.11,urcrnrlon=3.3,urcrnrlat=60.91,epsg = 5939, 
   resolution = 'h')

   lat = df['Latitude '].values
   lon = df['Longitude'].values
   wells = df['Well_Name'].values
   x,y = m(lon,lat)

   for i in range(len(lat)):
       plt.scatter(x, y, marker = 'o', c= df.Over_Pressure_MPa, cmap = "inferno_r", s = 200 )



   for i, label in enumerate(wells):
       plt.annotate(label, (lat[i], lon[i]))



   m.drawmapboundary(fill_color=None)

   m.fillcontinents(color=None,lake_color='aqua')
   m.drawcoastlines()

   plt.colorbar(label=r'Over Pressure')


   plt.show()
bigreddot
  • 33,642
  • 5
  • 69
  • 122
  • Can it help? [Matplotlib scatter plot with different text at each data point](https://stackoverflow.com/questions/14432557/matplotlib-scatter-plot-with-different-text-at-each-data-point) – magicarm22 Jul 14 '21 at 13:46
  • 1
    Does this answer your question? [Matplotlib scatter plot with different text at each data point](https://stackoverflow.com/questions/14432557/matplotlib-scatter-plot-with-different-text-at-each-data-point) – quamrana Jul 14 '21 at 13:48
  • Not exactly - I can't see how my code is different to that but my result is not the same – Porsche Adams Jul 14 '21 at 15:05
  • Maybe you need to change `lat[i], lon[i]` to `lon[i], lat[i]` here: `plt.annotate(label, (lat[i], lon[i]))` – magicarm22 Jul 14 '21 at 16:12
  • this gave me the error 'float obj is not callable' – Porsche Adams Jul 15 '21 at 10:01

0 Answers0