How to plot two lists in descending order based on y values?

前端 未结 3 546
甜味超标
甜味超标 2021-01-21 10:12

I have two lists. The first is a list of strings a

[\'Agriculture/Forestry/Fisheries/Veterinary Medicine\',
 \'Architectural and Town Planning\',
 \         


        
3条回答
  •  庸人自扰
    2021-01-21 10:23

    A simple data rearrangement approach:

    import matplotlib.pyplot as plt
    
    a = [
        'Agriculture/Forestry/Fisheries/Veterinary Medicine',
        'Architectural and Town Planning',
        'Business Administration and Related'
    ]
    
    b = [66667.0, 22283.0, 670091.5]
    
    b, a = zip(*sorted(zip(b, a), reverse=True))  # reverse sort data on 'b'
    
    c = range(len(b))
    
    fig = plt.figure()
    ax = fig.add_subplot(111)
    ax.bar(c, b)
    plt.xticks(c, a, rotation=90)
    plt.show()
    

提交回复
热议问题