0

I have two lists of latitude and longitude which latitude (xx) is like:

print(xx)

[['46.0'], ['-69.7'], ['-50.7'], ['-22.3'], ['-36.7'], ['65.1'], ['-26.3'], ['-47.5'], ['19.4'], ['-82.3'], ['50.8'], ['-63.5'], ['34.2'], ['65.1']]

I want to have a simple scatter plot of these latitudes and longitudes but I receive this error:

TypeError                                 Traceback (most recent call last)
<ipython-input-124-bc1e6bece6b3> in <module>
     15 m.drawmapboundary(fill_color='aqua')
     16 plt.title("distribution of the observation")
---> 17 x, y = map(yy, xx)
     18 map.scatter(x, y, marker='D',color='m')
     19 plt.show()

TypeError: 'list' object is not callable

-xx is list:

type(xx)

list

and

type(xx[0])

list
bah
  • 21
  • 6
  • If `m` is a Basemap instance, you are mixing `m` with the `map` builtin function (which has nothing to do with drawing in maps). You need to replace `map(yy, xx)` with `m(yy, xx)` and `map.scatter` with `m.scatter`. The reason why you get this TypeError is because the builtin function `map` expects a callable as first argument and an iterable as second argument. You are passing the list `yy` as first argument of `map`, and lists are not callable. But anyway, I think the whole point here is the mixing of `m` and `map`. – molinav Oct 20 '22 at 20:29

1 Answers1

0

Very straightforward way of doing this

import numpy as np
x = np.array([['46.0'], ['-69.7'], ['-50.7'], ['-22.3'], ['-36.7'], ['65.1'], ['-26.3'], ['-47.5'], ['19.4'], ['-82.3'], ['50.8'], ['-63.5'], ['34.2'], ['65.1']]).flatten()
y = x.astype(np.float)

print(y)
  • Thank you for your help. but 2 points to be mentioned: first, it is better to use np.float64. second, when I want to use the latitude variable name (xx) like: `x = np.array(xx).flatten()` I get the following error: `TypeError Traceback (most recent call last) TypeError: float() argument must be a string or a number, not 'list' The above exception was the direct cause of the following exception: ValueError: setting an array element with a sequence.` – bah Oct 20 '22 at 14:02
  • For the first point you may change to `np.float64`. Regarding the second point, you probably doesn't have your list shaped like a multidimensional array. Refer to this question to solve it.https://stackoverflow.com/questions/4674473/valueerror-setting-an-array-element-with-a-sequence – Mahery Ranaivoson Oct 20 '22 at 17:07