本文整理汇总了Python中matplotlib.dates.strpdate2num函数的典型用法代码示例。如果您正苦于以下问题:Python strpdate2num函数的具体用法?Python strpdate2num怎么用?Python strpdate2num使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了strpdate2num函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self,drift_object,times_to_combine_str,save_plots=True):
"""
Creates a drift_diagnositc object to load wavecal soln data into memory. Set's up outpath
"""
self.drift = drift_object
self.times_to_combine = [[strpdate2num("%Y%m%d-%H%M%S")(tstamp1),strpdate2num("%Y%m%d-%H%M%S")(tstamp2)] for [tstamp1,tstamp2] in times_to_combine_str]
self.drift.mastercalFNs, self.params = getCalFileNames(self.drift.params,'mastercal_','_drift')
self.save_plots=save_plots
intermDir=self.params['intermDir']
outdir=self.params['outdir']
if intermDir is None or intermDir is '':
intermDir = os.getenv('MKID_PROC_PATH', default="/Scratch")
if outdir is None or outdir is '':
outdir = '/waveCalSolnFiles'
self.outpath=intermDir+outdir+os.sep+self.drift.driftFNs[0].run+os.sep+'master_cals'
try:
os.mkdir(self.outpath)
os.mkdir(self.outpath+'/drift_study')
if self.save_plots:
os.mkdir(self.outpath+'/figs')
except:
pass
示例2: regis_plot
def regis_plot():
fig,ax=plt.subplots()
for item in ([ax.xaxis.label, ax.yaxis.label] + ax.get_xticklabels() + ax.get_yticklabels()):
item.set_fontsize(30)
days1, impressions = numpy.loadtxt("tempcsharp/owl.csv", unpack=True,
converters={ 0: mdates.strpdate2num('%Y-%m-%d')})
days_s1, impressions_t = numpy.loadtxt("tempcsharp/owl.csv", unpack=True,dtype='str')
impressions_log1 = []
print len(impressions)
for i in range(len(impressions)):
impressions_log1.append(sum(impressions[0:i]))
ax.plot_date(x=days1, y=impressions_log1, fmt="r-", label='owls', color='blue', lw=2)
days2, impressions = numpy.loadtxt("tempcsharp/sparrow.csv", unpack=True,
converters={ 0: mdates.strpdate2num('%Y-%m-%d')})
days_s2, impressions_t = numpy.loadtxt("tempcsharp/sparrow.csv", unpack=True,dtype='str')
impressions_log2 = []
print len(impressions)
for i in range(len(impressions)):
impressions_log2.append(sum(impressions[0:i]))
ax.plot_date(x=days2, y=impressions_log2, fmt="r-", label='sparrows', color='red', lw=2)
days3, impressions = numpy.loadtxt("tempcsharp/all.csv", unpack=True,
converters={ 0: mdates.strpdate2num('%Y-%m-%d')})
days_s3, impressions_t = numpy.loadtxt("tempcsharp/all.csv", unpack=True,dtype='str')
impressions_log3 = []
print len(impressions)
for i in range(len(impressions)):
impressions_log3.append(sum(impressions[0:i]))
ax.plot_date(x=days3, y=impressions_log3, fmt="r-", label='all', color='green', lw=2)
ax.set_xlabel("Registration time")
ax.set_ylabel("#Users")
days1 = list(days1)
days2 = list(days2)
days3 = list(days3)
output = open("datas/register.csv", 'w')
for i in range(len(days1)):
if days1[i] in days2 and days1[i] in days3:
j = days2.index(days1[i])
k = days3.index(days3[i])
output.write(days_s1[i]+", "+str(impressions_log1[i])+", "+str(impressions_log2[j])+", "+str(str(impressions_log3[k]))+"\n")
output.close()
#plt.ylim([0,5])
plt.legend(prop={'size':30}, loc = 2)
plt.grid(True)
plt.show()
sys.exit(1)
示例3: read
def read(self, url=None, fields=None, delimiter="\t"):
"""
Reads data from ODV formatted file.
Parameters
----------
url : string, optional
Full path and file name to save the data. If omitted,
assumes path indicated at sequence initialization.
fields : sequence, optional
Sets the fields to be saved. Default is to save all fields
in dataset.
Returns
-------
dat : array like
Structured array of file contents.
"""
if fields is not None:
raise ValueError("Not implemented yet.")
# Reads the content of file.
if url is None:
url = self.url
f = self._read_text_file(url)
# Splits all content lines and analyzes the header to extract
# additional information
header, fields, skip_header = self._get_header(f, comments="//", delimiter=delimiter)
keys = fields.keys()
# Sets data converters according to field names.
converters = dict()
for i, key in enumerate(keys):
if key == "YYYY-MM-DD":
converters[i] = strpdate2num("%Y-%m-%d")
elif key == "hh:mm":
converters[i] = strpdate2num("%H:%M")
# Converts data content in structured array using numpy.genfromtxt.
dat_keys = [b"{:d}".format(a) for a in range(len(keys))]
dat = genfromtxt(
url, delimiter=delimiter, skip_header=skip_header + 1, dtype=None, names=dat_keys, converters=converters
)
# Sets data in field container.
for dat_key, key in zip(dat_keys, keys):
fields[key].data = dat[dat_key]
# Updates class containers
self.fields = fields
# Update date and time.
T0 = 693596.0 # strpdate2num('%H:%M')('00:00')
self.time = fields["YYYY-MM-DD"].data + fields["hh:mm"].data - T0
# Returns data structured array.
return dat
示例4: populate_master_times_data
def populate_master_times_data(self):
if not hasattr(self, 'masterFNs'):
self.masterFNs,p = getCalFileNames(self.params,'mastercal_','_drift.h5')
if len(self.masterFNs)==0:
print "No master cal files found!"
return
print "Collecting master wvlcal start and end times for "+str(self.driftFNs[0].run)+'...'
self.master_start_time = np.zeros(len(self.masterFNs))
self.master_end_time = np.zeros(len(self.masterFNs))
for i in range(len(self.masterFNs)):
try:
driftFile=tables.openFile(self.masterFNs[i].mastercalDriftInfo(),mode='r')
drift_times = driftFile.root.params_drift.drifttimes.cols.wavecal[:]
drift_num_times = [strpdate2num("%Y%m%d-%H%M%S")(fname.split('_')[1].split('.')[0]) for fname in drift_times]
#print drift_times
self.master_start_time[i] = np.amin(drift_num_times)
self.master_end_time[i] = np.amax(drift_num_times)
driftFile.close()
except:
print '\tUnable to open: '+self.masterFNs[i].mastercalDriftInfo()
#print self.master_start_time
#print self.master_end_time
print "\tDone."
示例5: request_market_data
def request_market_data(self, timeframe, interval, symbol, sectype, \
exchange, currency=None, expiry=None, \
primexch=None, latestdate=None):
# Establish a connection
sys.stdout.write("\nCalling connection\n")
connection = ibConnection()
connection.register(self.ibhndl.my_callback_handler, \
message.historicalData)
connection.connect()
#Contract
contract = Contract()
contract.m_symbol = symbol
contract.m_secType = sectype
contract.m_exchange = exchange
contract.m_currency = currency
if primexch:
contract.m_primaryExch = primexch
if expiry:
contract.m_expiry = expiry
# Get historical data
rtnData = self.ibhndl.reqHistoricalData(contract, interval, connection,\
timeframe, latestdate)
connection.disconnect()
if not rtnData[0]:
sys.stderr.write("ERROR: No data return for %s : %s\n" % (symbol,\
interval))
return rtnData, ""
dateList = list()
stockFile = list()
for data, volume in zip(rtnData[0], rtnData[1]):
dateList = dateList + [data[0]]
dataStr = '%s, %s, %s, %s, %s, %s' % \
(strftime("%Y-%m-%d %H:%M:%S", \
localtime(int(str(data[0]))/1000)), data[1], \
data[2], data[3], data[4], str(volume[1]))
stockFile = stockFile + [dataStr]
convertStr = '%Y-%m-%d %H:%M:%S'
date, _, _, _, closep, volume = \
np.loadtxt(stockFile, delimiter=',', unpack=True, \
converters={0:mdates.strpdate2num(convertStr)})
#PATTERNS
retpat = []
try:
patterndb = PatternDB()
patterndb.add(HS())
patterndb.add(IHS())
retpat = patterndb.check(closep[-60:], date[-60:])
except Exception, excp:
sys.stderr.write("ERROR: PATTERNS failed with exception " \
"%s\n" % excp)
示例6: graph
def graph(csv_file, filename):
'''Create a line graph from a two column csv file.'''
unit = configs['unit']
date, value = np.loadtxt(csv_file, delimiter=',', unpack=True,
converters={0: mdates.strpdate2num('%H:%M:%S')}
)
fig = plt.figure(figsize=(10, 3.5))
fig.add_subplot(111, axisbg='white', frameon=False)
rcParams.update({'font.size': 9})
plt.plot_date(x=date, y=value, ls='solid', linewidth=2, color='#FB921D',
fmt=':'
)
title = "Sump Pit Water Level {}".format(time.strftime('%Y-%m-%d %H:%M'))
title_set = plt.title(title)
title_set.set_y(1.09)
plt.subplots_adjust(top=0.86)
if unit == 'imperial':
plt.ylabel('inches')
if unit == 'metric':
plt.ylabel('centimeters')
plt.xlabel('Time of Day')
plt.xticks(rotation=30)
plt.grid(True, color='#ECE5DE', linestyle='solid')
plt.tick_params(axis='x', bottom='off', top='off')
plt.tick_params(axis='y', left='off', right='off')
plt.savefig(filename, dpi=72)
示例7: graphRawFX
def graphRawFX():
date,bid,ask = np.loadtxt('GBPUSD1d.txt', unpack=True,
delimiter=',',
converters={0:mdates.strpdate2num('%Y%m%d%H%M%S')})
fig=plt.figure(figsize=(10,7))
ax1 = plt.subplot2grid((40,40), (0,0), rowspan=40, colspan=40)
ax1.plot(date,bid)
ax1.plot(date,ask)
plt.gca().get_yaxis().get_major_formatter().set_useOffset(False)
ax1.xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m-%d %H:%M:%S'))
#####
plt.grid(True)
for label in ax1.xaxis.get_ticklabels():
label.set_rotation(45)
#######
ax1_2 = ax1.twinx()
#ax1_2.plot(date, (ask-bid))
ax1_2.fill_between(date, 0, (ask-bid), facecolor='g',alpha=.3)
#ax1_2.set_ylim(0, 3*ask.max())
#######
plt.subplots_adjust(bottom=.23)
#plt.grid(True)
plt.show()
示例8: show_plot
def show_plot(times, values, np_test, name):
x_val, y_val = np.loadtxt(
np_test,
delimiter=',',
unpack=True,
converters={0: mdates.strpdate2num('%Y-%m-%d %H:%M:%S.%f')})
# x_val = times
# y_val = values
# plt.hold(False)
plt.title(name)
plt.xlabel('Time')
plt.ylabel('Values')
plt.plot_date(x=x_val,
y=y_val,
marker='o',
markerfacecolor='red',
fmt='b-',
label='value',
linewidth=2)
# plt.plot(x_val, y_val)
# plt.plot(x_val, y_val, 'or')
plt.savefig(os.path.join(MEDIA_FOLDER, 'plots', '%s.png' % name))
plt.clf()
plt.cla()
示例9: test11
def test11():
date = []; closep = []
with open('data/twtr-10y.csv') as csvfile:
reader = csv.DictReader(csvfile)
dateconv = strpdate2num('%Y/%m/%d')
for row in reader:
date.append(dateconv(row['date']))
closep.append(float(row['close']))
date = np.array(date)
closep = np.array(closep)
ipo = closep[-1]
fig = plt.figure()
ax1 = plt.subplot2grid((1,1),(0,0))
ax1.plot_date(date, closep, '-', label='price')
ax1.plot([],[], color='g', alpha=0.5, linewidth=3, label='gain')
ax1.plot([],[], color='r', alpha=0.5, linewidth=3, label='loss')
ax1.fill_between(date, closep, ipo, where=closep>ipo, facecolor='g', alpha=0.5)
ax1.fill_between(date, closep, ipo, where=closep<ipo, facecolor='r', alpha=0.5)
for label in ax1.xaxis.get_ticklabels():
label.set_rotation(45)
ax1.xaxis.label.set_color('c')
ax1.yaxis.label.set_color('r')
ax1.grid(True)
plt.subplots_adjust(bottom=0.20)
示例10: readPingJSON
def readPingJSON(file):
at_raw = json.load(open(file, 'r'))
at_prob_rtt = {}
for mes in at_raw:
prob_id = mes['prb_id']
if prob_id not in at_prob_rtt:
at_prob_rtt[prob_id] = {'src_ip': mes['from'],
'time_md': [],
'avg': [],
'min':[],
'max':[],
'loss':[],
'time_epc':[]}
epoch_time = mes['timestamp']
at_prob_rtt[prob_id]['time_epc'].append(epoch_time)
utc_string = time.strftime('%Y-%m-%d %H:%M:%S',time.gmtime(epoch_time))
mdate_time = mdates.strpdate2num('%Y-%m-%d %H:%M:%S')(utc_string)
at_prob_rtt[prob_id]['time_md'].append(mdate_time)
at_prob_rtt[prob_id]['min'].append(float(round(mes['min'])))
at_prob_rtt[prob_id]['avg'].append(float(round(mes['avg'])))
at_prob_rtt[prob_id]['max'].append(float(round(mes['max'])))
if mes['sent'] == 0:
at_prob_rtt[prob_id]['loss'].append(100)
else:
at_prob_rtt[prob_id]['loss'].append((1-float(mes['rcvd'])/mes['sent'])*100)
return at_prob_rtt
示例11: run
def run(infile, k, max_error=float('inf')):
# extract features and segmented data from CSV file
dates, data = pp.csv_import(infile)
segd1 = sgt.bottom_up(data,k,calc_error=sgt.sqr_residual)
segd2 = sgt.bottom_up(data,k,calc_error=sgt.relative_sqr_residual)
# output some statistics
print 'original data points: %d' % len(data)
print 'square residual data points: %d' % len(segd1)
print 'rel. square res data points: %d' % len(segd2)
# convert dates to matplotlib.dates
dates = map(mdates.strpdate2num('%Y-%m-%d'),dates)
# plot segmented time series versus original
fig, (orig_ts, seg1_ts, seg2_ts) = subplots(3, sharex=True)
fig.set_size_inches(8,10)
orig_ts.plot_date(dates,data,'b-')
orig_ts.set_title('original data')
seg_inds1, seg_vals1 = zip(*segd1)
seg_dates1 = [dates[i] for i in seg_inds1]
seg_inds2, seg_vals2 = zip(*segd2)
seg_dates2 = [dates[i] for i in seg_inds2]
seg1_ts.plot_date(seg_dates1, seg_vals1, 'r-')
seg1_ts.set_title('abs. residual error segmenting')
seg2_ts.plot_date(seg_dates2, seg_vals2, 'g-')
seg2_ts.set_title('rel. residual error segmenting')
# auto space the dates x-ticks
fig.autofmt_xdate()
show()
示例12: graphData
def graphData(stock):
try:
stockFile = stock+'.txt'
date, closep, highp, lowp, openp, volume = np.loadtxt(stockFile,delimiter=',',unpack=True,
converters={0: mdates.strpdate2num('%Y%m%d')})
fig = plt.figure()
ax1 = plt.subplot(1,1,1)
ax1.plot(date, openp)
ax1.plot(date, highp)
ax1.plot(date, lowp)
ax1.plot(date, closep)
ax1.xaxis.set_major_locator(mticker.MaxNLocator(10))
ax1.xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m-%d'))
for label in ax1.xaxis.get_ticklabels():
label.set_rotation(45)
plt.show()
except Exception,e:
print 'failed main loop',str(e)
示例13: bytespdate2num
def bytespdate2num(fmt, encoding='utf-8'):
strconverter = mdates.strpdate2num(fmt)
def bytesconverter(b):
s = b.decode(encoding)
return strconverter(s)
return bytesconverter
示例14: convert_date
def convert_date(date_format, encoding='utf-8'):
string_converter = mdates.strpdate2num(date_format)
def bytes_converter(b):
s = b.decode(encoding)
return string_converter(s)
return bytes_converter
示例15: comp_s
def comp_s(self,stock_name):
"""
Update the Stock information from the User Input
"""
self.str_msg_var.set(get_info(stock_name))
self.stock_name_var.set(stock_name)
start_d = self.start_date_entry.selection
end_d = self.end_date_entry.selection
if start_d == None:
start_d = calendar.datetime.datetime(2014,1,1)
if end_d == None:
end_d = calendar.datetime.datetime.now()
# print(start_d,end_d)
s = get_history(self.stock_name_var.get(), start_d.year, start_d.month, start_d.day, end_d.year, end_d.month, end_d.day)
fname = "newdoc.csv"
f = open(fname,"w+")
f.write(s)
f.close()
self.data = extract_data(fname)
figure1 = Figure(figsize=(6,4),dpi=100)
figure1a = figure1.add_subplot(111)
test_x = arange(0.0,3.0,0.01)
test_y = sin(2*pi*test_x)
x = list(map(mdates.strpdate2num("%m/%d/%Y"),map(lambda x: x[0],self.data[1:])))
y = list(map(lambda x: x[-1],self.data[1:]))
x = x[::-1]
y = y[::-1]
# print(x)
call(["python2", "orangehelper.py"])
# [reg,tpl] = analysetrend(fname,"trend.csv",0.7)
# print(reg)
# print(tpl)
# tpl = tpl[::-1]
tpl2 = []
xtpl = []
tpfn = open("orangetrend.txt")
for each in tpfn:
if each == "":
continue
line = each.strip().split(",")
tpl2.append(float(line[-1]))
xtpl.append(float(line[0]))
figure1a.plot_date(x,y,"b-")
figure1a.plot_date(xtpl,tpl2,"r-")
figure1.autofmt_xdate(bottom=0.2, rotation=30, ha='right')
dataPlot = FigureCanvasTkAgg(figure1, master=self.frame)
dataPlot.show()
dataPlot.get_tk_widget().grid(row=1,column=0,columnspan=2,sticky=W+N+S)
self.suggestion()