Length-1 Arrays and Python Scalars Via plt.text -


i'm trying use plt.text plot temperature values @ associated lat/lon points on plot.

after reviewing plt.text documentation, appears plotted value (third arg) has number , number has whole number, not number decimals.

below code i'm trying work , associated traceback error i'm receiving:

script code:

data = np.loadtxt('/.../.../.../tmax_day0', delimiter=',', skiprows=1) grid_x, grid_y = np.mgrid[-85:64:dx, 34:49:dx] temp = data[:,2] #print temp grid_z = griddata((data[:,1],data[:,0]), data[:,2], (grid_x,grid_y), method='linear') x,y = m(data[:,1], data[:,0]) # flip lat/lon grid_x,grid_y = m(grid_x,grid_y) #m.plot(x,y, 'ko', markersize=2)  def str_to_float(str):     try:        number = float(str)     except valueerror:        number = 0.0     return number  fmt = str_to_float(temp) #annotate point temperature on plot plt.text(grid_x, grid_y, fmt, fontdict=none) 

traceback error:

traceback (most recent call last): file "plotpoints.py", line 56, in <module> fmt = str_to_float(temp) file "plotpoints.py", line 51, in str_to_float number = float(str) typeerror: length-1 arrays can converted python scalars 

data sample text file tmax_day0:

latitude,longitude,value 36.65408,-83.21783,90 41.00928,-74.73628,92.02 43.77714,-71.75598,90 44.41944,-72.01944,88.8 39.5803,-79.3394,79 38.3154,-76.5501,86 38.91444,-82.09833,94 40.64985,-75.44771,92.6 41.25389,-70.05972,81.2 39.45202,-74.56699,90.88 

i able achieve plotting data values using following code:

for in range(len(temp)): plt.text(x[i], y[i], temp[i], va="top", family="monospace") 

result:

points


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -