Barchart with vertical labels in python/matplotlib

后端 未结 4 1021
栀梦
栀梦 2021-01-31 07:17

I\'m using matplotlib to generate a (vertical) barchart. The problem is my labels are rather long. Is there any way to display them vertically, either in the bar or above it or

4条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-31 07:47

    Please check out this link: https://python-graph-gallery.com/7-custom-barplot-layout/

    import matplotlib.pyplot as plt
    
    heights = [10, 20, 15]
    bars = ['A_long', 'B_long', 'C_long']
    y_pos = range(len(bars))
    plt.bar(y_pos, heights)
    # Rotation of the bars names
    plt.xticks(y_pos, bars, rotation=90)
    

    The result will be like this

    Hopefully, it helps.

提交回复
热议问题