How to plot multiple horizontal bars in one chart with matplotlib

前端 未结 2 1971
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-09 13:20

Can you help me figure out how to draw this kind of plot with matplotlib?

I have a pandas data frame object representing the table:

Graph       n            


        
2条回答
  •  再見小時候
    2020-12-09 13:54

    The question and answers are a bit old now. Based on the documentation this is much simpler now.

    >>> speed = [0.1, 17.5, 40, 48, 52, 69, 88]
    >>> lifespan = [2, 8, 70, 1.5, 25, 12, 28]
    >>> index = ['snail', 'pig', 'elephant',
    ...          'rabbit', 'giraffe', 'coyote', 'horse']
    >>> df = pd.DataFrame({'speed': speed,
    ...                    'lifespan': lifespan}, index=index)
    >>> ax = df.plot.barh()
    

提交回复
热议问题