`map.scatter` on basemap not displaying markers
Asked Answered
S

2

5

I have a map of Germany, and the coords of a few cities. plot displays the dots properly. I would like to use scatter instead, in order to be able to color the markets with respect to an other variable and then display a colorbar. The code runs in the console, but the dots are not visualized when I replace map.plot with map.scatter.

from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
import numpy as np


plt.figure(1)
map = Basemap(projection='merc',
              resolution='l',
              llcrnrlat=44.0,
              llcrnrlon=5.0,
              urcrnrlat=57.0,
              urcrnrlon=17)
map.drawcoastlines()
map.drawcountries()
map.fillcontinents(color='lightgray')
map.drawmapboundary()

long = np.array([ 13.404954,  11.581981,   9.993682,   8.682127,   6.960279,
         6.773456,   9.182932,  12.373075,  13.737262,  11.07675 ,
         7.465298,   7.011555,  12.099147,   9.73201 ,   7.628279,
         8.801694,  10.52677 ,   8.466039,   8.239761,  10.89779 ,
         8.403653,   8.532471,   7.098207,   7.216236,   9.987608,
         7.626135,  11.627624,   6.852038,  10.686559,   8.047179,
         8.247253,   6.083887,   7.588996,   9.953355,  10.122765])

lat = np.array([ 52.520007,  48.135125,  53.551085,  50.110922,  50.937531,
        51.227741,  48.775846,  51.339695,  51.050409,  49.45203 ,
        51.513587,  51.455643,  54.092441,  52.375892,  51.36591 ,
        53.079296,  52.268874,  49.487459,  50.078218,  48.370545,
        49.00689 ,  52.030228,  50.73743 ,  51.481845,  48.401082,
        51.960665,  52.120533,  51.47512 ,  53.865467,  52.279911,
        49.992862,  50.775346,  50.356943,  49.791304,  54.323293])

colors = np.array([ 2.72189792,  3.62138986,  1.7947676 ,  1.36524602,  1.75664228,
        3.0777491 ,  2.39580451,  1.17822874,  1.35503558,  2.28517658,
        3.66472978,  1.76467741,  0.72551119,  1.76997962,  4.49420944,
        2.34434288,  1.3243405 ,  2.35945794,  3.16147488,  2.94025564,
        1.68774158,  0.67602518,  1.60727613,  1.85608281,  3.57769226,
        1.33501838,  3.32549868,  2.95492675,  2.83391381,  2.33983198,
        2.59607424,  1.24260218,  1.89258818,  2.07508363,  3.03319927])

x, y = map(long, lat)
map.plot(x,y,'o')
plt.show()
Shum answered 23/1, 2015 at 10:6 Comment(0)
R
15

try adding "zorder" so that the points show up above the map:

    map.fillcontinents(color='lightgray',zorder=0)
Rianna answered 17/2, 2015 at 23:29 Comment(2)
I'm using the same snippet provided in the question. I used map.drawmapboundary(fill_color='lightblue') and then map.fillcontinents(color='lightgray', zorder=0). When scattering, I see the points which were invisible before, but the lightgray color is not shown - everything is lightblue (I just wanted the oceans to be lb). Any idea why this is happening?Lovemaking
This works for me thanks, but then it fills the whole map after, with the same as the ocean colour. Same issue as onofricamila... any solution?Parcenary
A
0

I also had the problem mentioned in the comment of the accepted answer (whole map becoming blue) so I ended up increasing the zorder of the plot instead :

map.plot(x,y,'o',zorder=9999)
Amadeo answered 18/5, 2022 at 12:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.