我正在创建一个SVG图像的世界与底图,我绘制了柏林市作为一个“控制点”(因为我想在那里手动放置一个圆。。。所以我有一个参考)。你知道吗
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()
在下一步中,我想通过编辑我创建的SVG文件的代码在SVG图像上手动放置一个圆。这可以通过在SVG图像代码末尾的</svg>
之前引入以下代码来实现。你知道吗
<circle fill="blue" cx="250" cy="470" r="2"/>
如何使用Python代码确定cx和cy的正确值,以将蓝点放置在Berlin所在的位置?你知道吗
我想我有mapWidth = 1080
和mapHeigth = 540
和xMax = 33973600
和yMax = 17231000
。你知道吗
这样我就可以计算cx = mapWidth - x/xMax*mapWidth
和类似的cy = mapHeigth - y/yMax*mapHeigth
。然而,这并没有把蓝点放在正确的位置,如果我考虑到底部和左边缘分别为72和152磅,也不是。有什么想法吗?你知道吗
看来你真的需要一个解决办法,我给你一个办法。你知道吗
注意:我不鼓励您手动操作
.svg
文件。但是,如果没有选择,那就让我们做吧!你知道吗解决方案假定非python进程不会更改表单中的文件。你知道吗
为了克服创建
.svg
文件(至少对我来说是黑框)的问题,您只需创建另一个绘制预期坐标的图像,将图像保存为临时.svg
文件,找到坐标点(在.svg
文件上),最后将它们添加到初始地图文件中。你知道吗我定义了3种方法: -
createMap
绘制地图并将输出另存为.png
文件 -get_svg_coordinates
:创建一个临时地图(.svg
文件),读取点坐标,删除临时文件,返回点坐标。 -add_circle
:在现有的.svg
映射文件上绘制圆。你知道吗下面是代码:(工作示例)
注:
我不熟悉
.svg
文件。为了回答这个问题,我按照预期在文件末尾添加了<circle fill="blue" cx="???" cy="???" r="2"/>
。然而,识别整个DOM<g id="line2d_1">
并复制过去可能更好。这个片段只适用于一个图像,我让你概括一组点。
相关问题 更多 >
编程相关推荐