我有一个python文件,我在其中使用gmplot在gmap上创建自定义标记。我将其保存为HTML文件。当我在电脑中打开文件时,它工作正常。然而,当我试图在手机上打开它,或通过电子邮件发送它,并试图在另一台计算机上打开它时,所有的PIN码都消失了。地图将加载到它应该位于的正中心位置。这是密码
import gmplot
import pandas as pd
import random
newdir = r'C:\Users\.spyder-py3'
newfile = r'\EWMP List 2019 Addresses.xlsx'
df=pd.read_excel(newdir+newfile)
#colors=pd.read_csv(newdir+r'\html_colors.csv')
#color_list=[]
# html colors is a csv file with hexa codes for different colors
# I am suppressing the randomizer and hardcoding the colors here to see if that works. It doesn't
#for i, k in enumerate(random.sample(range(len(colors)),10)):
# color_list.append(colors['Hex Code'][k])
placetypelist=df['placetype'].unique().tolist()
#In the original code, I cycle through the placetype_list and color_list append them to the color_dict as #key and item
# As you can see below I am hardcoding this dictionary
color_dict={'Greenway': '#FF0000',
'Miscellaneous': '#AFEEEE',
'Natural Restoration': '#DA70D6',
'School': '#3CB371',
'golf course': '#191970',
'green street': '#EE82EE',
'park and open space': '#808080',
'parking lot': '#F8F8FF',
'school': '#C71585',
'unknown land parcel': '#1E90FF'}
#for i in range(len(color_list)):
# color_dict[placetypelist[i]] = (color_list[i])
latlist=df['resolved_lat'].tolist()
lnglist=df['resolved_lng'].tolist()
gmaps=gmplot.GoogleMapPlotter(latlist[0],lnglist[0],zoom=13,apikey=<myAPIkeyasstring>)
for i in range(len(latlist)):
gmaps.marker(latlist[i],lnglist[i],c=color_dict[df['placetype'][i]], title=str(i)+df['placetype'][i])
gmaps.draw(newdir+r'\laconcise_alt.html')
我想我找到了答案,这要感谢github链接中的出色工作
t.ly/DZX03
假设您使用的是我使用的逻辑,通过一个用于html颜色的CSV文件处理六进制代码。通常,matplotlib中会使用csv颜色(我想是140)。gmplot模块有一个color_dict文件,该文件未更新所有matplotlib颜色。如果您使用的hexa代码不在列表中,它将抛出一个错误。所以,在你像我一样处理一个随机的csv文件之前,请先更新你那端的color_dict文件。我认为更好的选择是从您的代码中的color_dict文件导入html颜色代码并使用它
相关问题 更多 >
编程相关推荐