How to plot a very simple bar chart (Python, Matplotlib) using input *.txt file?

前端 未结 3 1563
孤街浪徒
孤街浪徒 2020-12-08 15:04

I use Python 2.7 and matplotlib. I have a *.txt data file :

0 14-11-2003
1 15-03-1999
12 04-12-2012
33 09-05-2007
44 16-08-1998
55 25-07-2001
76 31-12-2011
8         


        
3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-08 15:31

    This code will do what you're looking for. It's based on examples found here and here.

    The autofmt_xdate() call is particularly useful for making the x-axis labels readable.

    import numpy as np
    from matplotlib import pyplot as plt
    
    fig = plt.figure()
    
    width = .35
    ind = np.arange(len(OY))
    plt.bar(ind, OY, width=width)
    plt.xticks(ind + width / 2, OX)
    
    fig.autofmt_xdate()
    
    plt.savefig("figure.pdf")
    

    enter image description here

提交回复
热议问题