python - Plotting with more colors in matplotlib -


i trying plot scatter plot using matplotlib, getting " indexerror: pop empty list" error , not sure how fix it.

import matplotlib.pyplot plt import matplotlib import numpy np import time import itertools  d = {'5000cca229d10d09': {374851: 1}, '5000cca229cf3f8f': {372496:3},'5000cca229d106f9': {372496: 3, 372455: 2}, '5000cca229d0b3e4': {380904: 2, 380905: 1, 380906: 1, 386569: 1}, '5000cca229d098f8': {379296: 2, 379297: 2, 379299: 2, 379303: 1, 379306: 1, 379469: 1, 379471: 1, 379459: 1, 379476: 1, 379456: 4, 379609: 4}, '5000cca229d03957': {380160: 3, 380736: 3, 380162: 1, 380174: 1, 381072: 2, 379608: 2, 380568: 3, 380569: 1, 380570: 1, 379296: 3, 379300: 1, 380328: 3, 379306: 1, 380331: 1, 379824: 2, 379825: 1, 379827: 1, 380344: 1, 379836: 1, 379456: 3, 380737: 1, 380739: 1, 379462: 1, 379476: 1, 379992: 3, 379609: 1, 379994: 1, 379611: 1, 379621: 1, 380006: 1, 380904: 3, 380905: 1, 380907: 1, 380535: 3, 380536: 1, 380538: 1}, '5000cca229cf6d0b': {372768: 10, 372550: 15, 372616: 14, 372617: 20, 372653: 3, 372505: 2}, '5000cca229cec4f1': {372510: 132}} colors = list("rgbcmyk")   data_dict in d.values():    x = data_dict.keys()    #print x    #x= time.asctime(time.localtime(x))    y = data_dict.values()    #plt.scatter(x,y,color=colors.pop(),s = 60)    plt.scatter(x,y,color=colors.pop(),s = 90, marker='^')    plt.ylabel("errors" , fontsize=18, color="green")    plt.xlabel("occured on",fontsize=18, color="green")    plt.title("ddn23b", fontsize=25, color="blue")    plt.gca().get_xaxis().get_major_formatter().set_useoffset(false)    plt.xticks(rotation='vertical')     #plt.ylim(min(y),max(y))    #plt.grid()  #for x, y in dict(itertools.chain(*[item.items() item in d.values()])).items(): #    plt.text(x, y, time.strftime("%m/%d/%y, %h:%m:%s", time.localtime(x*3600)),     ha='center', va='top', rotation='vertical', fontsize = '11', fontstyle = 'italic', color = '#844d4d')  plt.xticks(plt.xticks()[0], [time.strftime("%m/%d/%y, %h:%m:%s", time.localtime(item))     item in plt.xticks()[0]*3600]) plt.legend(d.keys()) mng = plt.get_current_fig_manager() mng.resize(*mng.window.maxsize()) plt.subplots_adjust(bottom=.24,right=.98,left=0.03,top=.89) plt.grid() plt.show() 

i have several data sets d, , d dictionary. when data set smaller, works without errors. when data set large, runs out of collars. how add more colors list every key in "d" gets own color.

feel free edit code , make suggestions.

colormaps callable. when passed float between 0 , 1, returns rgba color:

in [73]: jet = plt.cm.jet  in [74]: jet(0.5) out[74]: (0.49019607843137247, 1.0, 0.47754585705249841, 1.0) 

so, generate len(d) number of colors passing numpy array np.linspace(0, 1, len(d)) colormap:

jet = plt.cm.jet colors = jet(np.linspace(0, 1, len(d))) 

the colors selected equally spaced along colormap gradient.


import matplotlib.pyplot plt import numpy np import time  d = {'5000cca229d10d09': {374851: 1}, '5000cca229cf3f8f': {372496:3},'5000cca229d106f9': {372496: 3, 372455: 2}, '5000cca229d0b3e4': {380904: 2, 380905: 1, 380906: 1, 386569: 1}, '5000cca229d098f8': {379296: 2, 379297: 2, 379299: 2, 379303: 1, 379306: 1, 379469: 1, 379471: 1, 379459: 1, 379476: 1, 379456: 4, 379609: 4}, '5000cca229d03957': {380160: 3, 380736: 3, 380162: 1, 380174: 1, 381072: 2, 379608: 2, 380568: 3, 380569: 1, 380570: 1, 379296: 3, 379300: 1, 380328: 3, 379306: 1, 380331: 1, 379824: 2, 379825: 1, 379827: 1, 380344: 1, 379836: 1, 379456: 3, 380737: 1, 380739: 1, 379462: 1, 379476: 1, 379992: 3, 379609: 1, 379994: 1, 379611: 1, 379621: 1, 380006: 1, 380904: 3, 380905: 1, 380907: 1, 380535: 3, 380536: 1, 380538: 1}, '5000cca229cf6d0b': {372768: 10, 372550: 15, 372616: 14, 372617: 20, 372653: 3, 372505: 2}, '5000cca229cec4f1': {372510: 132}}  jet = plt.cm.jet colors = jet(np.linspace(0, 1, len(d)))  fig, ax = plt.subplots() color, data_dict in zip(colors, d.values()):    x = data_dict.keys()    y = data_dict.values()    ax.scatter(x,y,color=color, s = 90, marker='^')    plt.ylabel("errors" , fontsize=18, color="green")    plt.xlabel("occured on",fontsize=18, color="green")    plt.title("ddn23b", fontsize=25, color="blue")    ax.get_xaxis().get_major_formatter().set_useoffset(false)    plt.xticks(rotation='vertical')    plt.xticks(plt.xticks()[0],            [time.strftime("%m/%d/%y, %h:%m:%s", time.localtime(item))             item in plt.xticks()[0]*3600])  plt.legend(d.keys()) plt.subplots_adjust(bottom=.24,right=.98,left=0.03,top=.89) plt.grid() plt.show() 

enter image description here


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -