How to draw an arrow on an Basemap object using matplotlib?
Asked Answered
J

1

6

I have been trying to draw arrows on a Basemap object for quite a while already. I found help for drawing lines on the map, but it seems that the arrowhead just does not want to appear.

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

map = Basemap(projection='merc', lat_0 = 57, lon_0 = -135,
resolution = 'i', area_thresh = 0.1,
llcrnrlon=-136.25, llcrnrlat=56.0,
urcrnrlon=-134.25, urcrnrlat=58)

map.drawcoastlines()
map.drawcountries()
map.drawmapboundary()

lon = -135.3318
lat = 57.0799
x,y = map(lon, lat)
x2, y2 = map(lon+0.5,lat+0.5)

plt.arrow(x,y,x2-x,y2-y,fc="k", ec="k", linewidth = 4, head_width=10, head_length=10)
plt.show()

As a result I only get: https://i.sstatic.net/5aKKq.png You can see a little bit of a head, but almost nothing. Am I just to stupid to get the arguments right? I have been fiddling around for quite a while...

EDIT: Yes I was just to stupid to get the arguments right. I put 10000 for head width and length and an arrow was visible.. I think because of basemap it calculates in metres and that threw me off.

Jolynjolynn answered 13/1, 2015 at 16:12 Comment(0)
J
3

I just did not put the arguments right. On the scale used it hat to be at least 10000 head_width and head_length

Jolynjolynn answered 13/1, 2015 at 16:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.