Plotting a dictionary with multiple values per key

前端 未结 3 1643
广开言路
广开言路 2021-01-20 03:42

I have a dictionary that looks like this:

1: [\'4026\', \'4024\', \'1940\', \'2912\', \'2916], 2: [\'3139\', \'2464\'], 3:[\'212\']...

For

3条回答
  •  终归单人心
    2021-01-20 04:21

    You need to construct your list of Xs and Ys manually:

    In [258]: b={1: ['4026', '4024', '1940', '2912', '2916'], 2: ['3139', '2464'], 3:['212']}
    
    In [259]: xs, ys=zip(*((int(x), k) for k in b for x in b[k]))
    
    In [260]: xs, ys
    Out[260]: ((4026, 4024, 1940, 2912, 2916, 3139, 2464, 212), (1, 1, 1, 1, 1, 2, 2, 3))
    
    In [261]: plt.plot(xs, ys, 'ro')
         ...: plt.show()
    

    resulting: enter image description here

提交回复
热议问题