我在使用Python的gmplot库时遇到了麻烦,因为我没有使用该库的详尽指导。更具体地说,我在散布3种不同颜色的Google Map时遇到了麻烦。以下是我的代码示例。
import numpy as np
import matplotlib.pyplot as plt
from gmplot import gmplot
import os
import pandas as pd
#This is the filename of the Excel that contains the longitudes and latitudes
file ='CensusTrackCluster.xlsx'
#Input the Excel file using Panda
xl = pd.ExcelFile(file)
#Parse the sheet that contains the latitudes and longitudes into a data frame
df = xl.parse('Sheet4')
#Possible colors
colors = ['red','blue','green','purple','orange','yellow','pink','white']
#Subset of the latitudes and longitudes
k1,k2 = df['lats.1'].tolist()[0:4], df['lngs.1'].tolist()[0:4]
j1,j2 = df['lats'].tolist()[0:4], df['lngs'].tolist()[0:4]
m1,m2 = df['lats.2'].tolist()[0:4], df['lngs.2'].tolist()[0:4]
#Plot the scatter plot on the map
gmap = gmplot.GoogleMapPlotter(34.053132754059298, -118.273844602339, 10)
gmap.scatter(k1,k2, colors[0], size=60, marker=False)
gmap.scatter(j1,j2, colors[1], size=60, marker=False)
gmap.scatter(m1,m2, colors[1], size=60, marker=False)
gmap.draw("test.html")
当我排列函数的顺序时,最多可以给我2种颜色,例如
gmap.scatter(k1,k2, colors[0], size=60, marker=False)
gmap.scatter(m1,m2, colors[1], size=60, marker=False)
gmap.scatter(j1,j2, colors[1], size=60, marker=False)
谁能解释我如何解决这个问题?还是有其他方法可以在Python中使用2种以上的不同颜色在Google Map上散布图?