Python Forum

Full Version: Plotting datas
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,

I am completely new with matplotlib. I would like to create a graph (with points), where every data on x axis is a date and y is a float number.
The datas are coming from a file, looks like (first column date, second intensity value):
20180824 289520.0
20180818 405328.0
20180824 289520.0

I am trying with this code, but I get trouble because of the date format. Can anyone help me?
x = []
y = []
with open('../MLI_values/mli_value_XYZ_SUM.txt', 'r') as data_file:
    plots = csv.reader(data_file, delimiter=' ')
    for raw in plots:
        x.append(float(raw[0]))
        print(x)
        y.append(float(raw[1]))
        print(y)
plt.plot(x, y, label='DATE')
plt.xlabel('x')
plt.ylabel('y')
plt.title('blablabla')
plt.legend()
plt.show()
What exactly is the error you are getting? Please post the full text of the traceback.
Not sure what you are expecting, but the odd format issue around your date value is due to the float cast. remove the float cast around your date column and you should see what you expect to see.