I am creating an SVG image of the world with basemap on which I plot the city of Berlin as a "control point" (because I would like to place a circle there manually ... so I have a reference).
from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
# Berlin & New York & Sydney
lats = [52.516667] #[52.516667, 40.730610]
lons = [13.388889] # [13.388889, -73.935242]
plt.figure(figsize=(15,15/2))
m = Basemap(projection='robin', lon_0=0, resolution='c')
m.drawcountries(color='#ffffff', linewidth=0.75)
m.fillcontinents(color='#c0c0c0', lake_color='#e6f5ff')
m.drawmapboundary(fill_color='#e6f5ff', linewidth=1, color='#000000') # Ocean
x,y = m(lons,lats)
plt.plot(x, y, 'bo', color='r', markersize=5)
plt.savefig("basemap.svg", figsize=(24,12))
plt.show()
In a next step, I would like to manually place a circle on the SVG image by editing the code of the SVG file that I've created. This can be done by introducing the following code before </svg> at the end of the SVG image code.
<circle fill="blue" cx="250" cy="470" r="2"/>
How can I determine the correct value for cx and cy with my Python code to place the blue dot where Berlin is located?
I figured I have a mapWidth = 1080 and a mapHeigth = 540 and xMax = 33973600 and yMax = 17231000.
In this way I could calculate cx = mapWidth - x/xMax*mapWidth and analogously cy = mapHeigth - y/yMax*mapHeigth. However, this does not place the blue dot at the correct position also not if I consider a bottom and left margin of 72 and 152 pt, respectively. Any ideas?
from Basemap m(lats,lons) to svg cx and cy
No comments:
Post a Comment