Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/330.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在map.plot kwargs for python中使用多种颜色_Python_Matplotlib_Plot_Colors - Fatal编程技术网

如何在map.plot kwargs for python中使用多种颜色

如何在map.plot kwargs for python中使用多种颜色,python,matplotlib,plot,colors,Python,Matplotlib,Plot,Colors,我试图在地图上绘制事件数据的纵横图 在这段代码中,我需要十个不同的颜色参数来使它工作,我已经用完了颜色。 我如何解决这个问题 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,201

我试图在地图上绘制事件数据的纵横图

在这段代码中,我需要十个不同的颜色参数来使它工作,我已经用完了颜色。 我如何解决这个问题

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元组,并将plot命令编辑为:

plot(x,y,color=getcolor(count),markersize=6)

输出是

十种不同颜色的标记的所需输出为


请注意您可以在
color=
关键字参数中使用任何颜色,例如像
“5742FD”
这样的十六进制RGB字符串


有关详细信息,请参阅Matplotlib文档:

使用rgb值而不是读取颜色=getcolor(计数)标记的类型是否已修复?总是“o”?谢谢@bigbounty,已经做到了谢谢@JayParikh已经做到了。地图显示的是一个由线组成的迷宫,而不是点,你能帮我弄清楚吗