Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Plotting datas
#1
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()
Reply
#2
What exactly is the error you are getting? Please post the full text of the traceback.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  time setup for realtime plotting of serial datas at high sampling rate alice93 6 3,648 Jan-07-2022, 05:41 PM
Last Post: deanhystad
  iterate and print json datas enigma619 1 1,890 Apr-01-2020, 11:48 AM
Last Post: buran
  Datas are not insert into database aravinth 1 2,153 Dec-21-2019, 04:17 PM
Last Post: buran
  How to put together datas into a file? Krszt 1 1,894 Nov-07-2018, 04:06 PM
Last Post: ichabod801
  How to put together datas from different files Krszt 3 2,335 Oct-31-2018, 07:37 AM
Last Post: Krszt
  How to write datas into a file? Krszt 2 2,365 Oct-25-2018, 01:45 PM
Last Post: Krszt
  how to retrieve datas with Overpass API python wrapper apollo 0 2,888 Oct-15-2017, 02:27 PM
Last Post: apollo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020