我正在尝试在传单地图中显示固定大小的圆圈。
我尝试使用.add_artist()
(请参阅here),我现在正尝试使用.add_patch()
import mplleaflet
import matplotlib.pyplot as plt
import matplotlib as mpl
fig, ax = plt.subplots()
x = 2.363561
y = 48.951918
r = 20
circle1 = mpl.patches.Circle((x,y), radius=r)
circle2= plt.Circle((x, y), r, color='r')
#ax.add_patch(circle1)
#ax.add_patch(circle2)
mplleaflet.show(fig=ax.figure)
您可以尝试取消注释两个注释行中的一行,取消注释哪一行无关紧要,弹出相同的错误。
这是我得到的痕迹:
Traceback (most recent call last):
File "<ipython-input-81-1fdd7f4a9d12>", line 16, in <module>
mplleaflet.show(fig = ax.figure)
File "C:\ProgramData\Anaconda3\lib\site-packages\mplleaflet\_display.py", line 180, in show
save_html(fig, fileobj=f, **kwargs)
File "C:\ProgramData\Anaconda3\lib\site-packages\mplleaflet\_display.py", line 131, in save_html
html = fig_to_html(fig, **kwargs)
File "C:\ProgramData\Anaconda3\lib\site-packages\mplleaflet\_display.py", line 84, in fig_to_html
exporter.run(fig)
File "C:\ProgramData\Anaconda3\lib\site-packages\mplleaflet\mplexporter\exporter.py", line 51, in run
self.crawl_fig(fig)
File "C:\ProgramData\Anaconda3\lib\site-packages\mplleaflet\mplexporter\exporter.py", line 118, in crawl_fig
self.crawl_ax(ax)
File "C:\ProgramData\Anaconda3\lib\site-packages\mplleaflet\mplexporter\exporter.py", line 138, in crawl_ax
self.draw_patch(ax, patch)
File "C:\ProgramData\Anaconda3\lib\site-packages\mplleaflet\mplexporter\exporter.py", line 227, in draw_patch
mplobj=patch)
File "C:\ProgramData\Anaconda3\lib\site-packages\mplleaflet\leaflet_renderer.py", line 125, in draw_path
rings = list(iter_rings(data, pathcodes))
File "C:\ProgramData\Anaconda3\lib\site-packages\mplleaflet\utils.py", line 14, in iter_rings
raise ValueError('Unrecognized code: {}'.format(code))
ValueError: Unrecognized code: C
关于如何解决这个问题的任何想法?
===========================
编辑:
为了看看会发生什么,我尝试做的事情与this相同,后者正在改变
elif code == 'L': ring.append(point)
到
elif code == 'L' or code == 'Z' or code == 'S' or code == 'C': ring.append(point)
在mplleaflet\utils.py
第11和12行。这是我得到的:
===========================
编辑2回答评论
mpl.patches.Rectangle
和plt.Rectangle
显示:
rect1 = mpl.patches.Rectangle((x,y), 1, 1, color = 'r')
rect2 = plt.Rectangle((x, y), 1, 1, fc='r')
这似乎适合纬度为1度,经度为1度的矩形(见here)(也许?看起来有点小)。
关于Polygons
,嗯......至少他们出现了,但我猜有一个预测问题:
regpol1 = mpl.patches.RegularPolygon((x,y), 100, radius=r, color = 'r')
cirpol1 = mpl.patches.CirclePolygon((x +50,y), radius=r, color = 'b')