I have 2 numpy arrays with (time and date), and the third with rain. At the end I would like to plot all the info at a xy-plot with matplotlib! This i what I got so far
import os
import time
from datetime import datetime
import time
import numpy as np
import matplotlib.dates as mdates
import matplotlib.pyplot as plt
date = np.array(["01.06.2015", "01.06.2015", "01.06.2015"], dtype=object)
time = np.array(["12:23:00", "14:54:00", "14:56:00"], dtype=object)
# Rain
rain = np.array([2.544, 1.072, 1.735]
# Calculations to make one array of time and date,
# called timestamp
A = np.vstack((date, time))
A_transp = A.transpose()
A_transp.shape
A_transp.type
So at the end as mentioned I would like to have an (x,y)-Plot, with timestamps(so time and date combined as an array of floating point numbers and the rain on the other axes.
Thank you for your help
Markus
Thank you for your help, but I do not come to a conclusion! Further stepps I did!
# Get a new .out file, to get a time tuple
# see strptime.
# Finally I would like to make a floating point number out of the
# timetuple, to plot the hole thing!
#
mydata = np.savetxt('A_transp.out', A_transp
,fmt="%s")
# Dateconv
dateconv = lambda s: datetime.strptime(s, '%d.%m.%Y %H:%M:%S')
# ColNames
col_names = ["Timestamp"]
# DataTypes
dtypes = ["object"]
# Read in the new file
mydata_next = np.genfromtxt('A_transp.out', delimiter=None,
names=col_names, dtype=dtypes, converters={"Timestamp":dateconv})
So after the np.genfromtxt following error message appears
Traceback (most recent call last):
File "parsivel.py", line 155, in <module>
names=col_names, dtype=dtypes, converters={"Timestamp":dateconv})
File "/home/unix/anaconda2/lib/python2.7/site-
packages/numpy/lib/npyio.py", line 1867, in genfromtxt
output = np.array(data, dtype)
ValueError: Setting void-array with object members using buffer.
What I would try after that would be the following.
#B = mdates.strpdate2num(mydata_next) # fail
#B = time.mktime(mydata_next) # fail
#B = plt.dates.date2num(mydata_next) # fail
And finally I would like to plot the following
# Plot
# Fail
#plt.plot_date(mydata_next, rain)
#plt.show()
But at the moment all the plots fail, because I can not make a time tuple out of A_transp! Maybe also the strptime function is not right here, or there is another way as the detour via np.savetxt and the try of rearanging A_transp?