【发布时间】:2017-07-22 07:16:08
【问题描述】:
我正在尝试在地图上绘制经纬度事件数据。
在这段代码中,我需要十个不同的颜色参数才能使它工作,我已经用完了颜色。 我该如何解决这个问题?
lon=[]
lat=[]
def getcolor(c):
if c in [1970,1980,1990,2000,2010]:
return 'bo'
if c in [1971,1981,1991,2001,2011]:
return 'go'
if c in [1972,1982,1992,2002,2012]:
return 'ro'
if c in [1973,1983,1993,2003,2013]:
return 'co'
if c in [1974,1984,1994,2004,2014]:
return 'mo'
if c in [1975,1985,1995,2005,2015]:
return 'yo'
if c in [1976,1986,1996,2006,2016]:
return 'ko'
else :
return 'wo' # I have run out of color arguments
def map_year(year):
count=year
while count>year-10:
lon=pd.Series(df.longitude[df['iyear']==count])
lat=pd.Series(df.latitude[df['iyear']==count])
x,y = map(lon.tolist(),lat.tolist())
map.plot(x, y, getcolor(count), markersize=6)
plt.hold(True)
count=count-1
plt.show()
map_year(2016)
更新 谢谢你的投入。。 现在我在 getcolor 函数中将颜色格式更改为 rgb 元组,并将绘图命令编辑为:
map.plot(x, y,color=getcolor(count), markersize=6)
输出是 current ouput
十种不同颜色标记的期望输出是 desired output
请指教
【问题讨论】:
-
改用 rgb 值
-
尝试颜色 = getcolor(count)
-
标记的类型是固定的吗?总是'o'?
-
谢谢@bigbounty,已经完成了
-
感谢@JayParikh 做到了。地图变成了迷宫而不是点,你能帮忙弄清楚吗
标签: python matplotlib plot colors