Python Forum
Plotting datas - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Plotting datas (/thread-13769.html)



Plotting datas - Krszt - Oct-31-2018

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()



RE: Plotting datas - ichabod801 - Oct-31-2018

What exactly is the error you are getting? Please post the full text of the traceback.


RE: Plotting datas - Davis4109 - Oct-31-2018

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.