示例#1
0
def plot_ts(series, lib="matplotlib"): #*args
    if lib == "matplotlib":
        import matplotlib.pyplot as plt
        import scikits.timeseries.lib.plotlib as tpl
        fig = tpl.tsfigure()
        fsp = fig.add_tsplot(111)
        fsp.tsplot(series, '-')
        plt.show()
    else:
        # guiqwt
        #raise NotImplementedError
        pass
import numpy as np
import matplotlib.pyplot as plt
import scikits.timeseries as ts
import scikits.timeseries.lib.plotlib as tpl

# generate some random data
num_points = 12
data = np.cumprod(1 + np.random.normal(0, 1, num_points) / 100)
series = ts.time_series(data, start_date=ts.now('d') - num_points)
fig = tpl.tsfigure()
fsp = fig.add_tsplot(111)
fsp.tsplot(series, '-')
fsp.set_xlim(int(series.start_date), int(series.end_date))
fsp.set_title('%i days' % num_points)
plt.show()
import scikits.timeseries as ts
import scikits.timeseries.lib.plotlib as tplt

data = sm.datasets.macrodata.load(as_pandas=False)
data = data.data

### Create Timeseries Representations of a few vars

dates = ts.date_array(start_date=ts.Date('Q', year=1959, quarter=1),
                      end_date=ts.Date('Q', year=2009, quarter=3))

ts_data = data[['realgdp', 'realcons', 'cpi']].view(float).reshape(-1, 3)
ts_data = np.column_stack((ts_data, (1 - data['unemp'] / 100) * data['pop']))
ts_series = ts.time_series(ts_data, dates)

fig = tplt.tsfigure()
fsp = fig.add_tsplot(221)
fsp.tsplot(ts_series[:, 0], '-')
fsp.set_title("Real GDP")
fsp = fig.add_tsplot(222)
fsp.tsplot(ts_series[:, 1], 'r-')
fsp.set_title("Real Consumption")
fsp = fig.add_tsplot(223)
fsp.tsplot(ts_series[:, 2], 'g-')
fsp.set_title("CPI")
fsp = fig.add_tsplot(224)
fsp.tsplot(ts_series[:, 3], 'y-')
fsp.set_title("Employment")

# Plot real GDP
#plt.subplot(221)
import numpy as np
import matplotlib.pyplot as plt
import scikits.timeseries as ts
import scikits.timeseries.lib.plotlib as tpl

# generate some random data
num_points = 250
data = np.cumprod(1 + np.random.normal(0, 1, num_points)/100)
series = ts.time_series(data, start_date=ts.now('d')-num_points)
fig = tpl.tsfigure()
fsp = fig.add_tsplot(111)
fsp.tsplot(series, '-')
fsp.set_xlim(int(series.start_date), int(series.end_date))
fsp.set_title('%i days' % num_points)
plt.show()
示例#5
0
data = sm.datasets.macrodata.load(as_pandas=False)
data = data.data


### Create Timeseries Representations of a few vars

dates = ts.date_array(start_date=ts.Date('Q', year=1959, quarter=1),
    end_date=ts.Date('Q', year=2009, quarter=3))

ts_data = data[['realgdp','realcons','cpi']].view(float).reshape(-1,3)
ts_data = np.column_stack((ts_data, (1 - data['unemp']/100) * data['pop']))
ts_series = ts.time_series(ts_data, dates)


fig = tplt.tsfigure()
fsp = fig.add_tsplot(221)
fsp.tsplot(ts_series[:,0],'-')
fsp.set_title("Real GDP")
fsp = fig.add_tsplot(222)
fsp.tsplot(ts_series[:,1],'r-')
fsp.set_title("Real Consumption")
fsp = fig.add_tsplot(223)
fsp.tsplot(ts_series[:,2],'g-')
fsp.set_title("CPI")
fsp = fig.add_tsplot(224)
fsp.tsplot(ts_series[:,3],'y-')
fsp.set_title("Employment")


示例#6
0
                continue
            dates.append(row.split(',')[0])
        #dates = data[:, 0].astype(int).tolist()
        dates = [parse_date(str(d)) for d in dates]
        ELECTRIC = time_series(masked_less(data[:, 0], 0), dates)
        GAS = time_series(masked_less(data[:, 1], 0), dates)
        WATER = time_series(masked_less(data[:, 2], 0), dates)
        START = dates[0]
        END = dates[-1]
        CLIMATE = get_nm_climate(
            start_date='%i%.2i%.2i' % (START.year, START.month, START.day),
            end_date='%i%.2i%.2i' % (END.year, END.month, END.day))
        CLIMATE.tofile('/tmp/test.txt')
        MAX_TEMP, MIN_TEMP, ACCUM_PRECIP = CLIMATE.split()

        FIG = tpl.tsfigure(figsize=(10, 7))
        FIG.subplots_adjust(hspace=0.1)

        GAS_PLOT = FIG.add_tsplot(313)
        GAS_PLOT.tsplot(backward_fill(GAS), zorder=20)
        GAS_PLOT.set_ylabel('Gas usage, therms')
        GAS_PLOT.grid(linestyle='-', color='0.9', zorder=0)
        TEMP_PLOT = GAS_PLOT.add_yaxis(position='right')
        TEMP_PLOT.tsplot(MIN_TEMP, color='0.5', zorder=10)
        TEMP_PLOT.tsplot(MAX_TEMP, color='0.5', zorder=10)
        TEMP_PLOT.set_ylabel(u'Temperature range, \u2109F')

        WATER_PLOT = FIG.add_tsplot(311, sharex=GAS_PLOT)
        WATER_PLOT.tsplot(backward_fill(WATER * 748), zorder=20)
        WATER_PLOT.grid(linestyle='-', color='0.9', zorder=1)
        WATER_PLOT.set_xticklabels(WATER_PLOT.get_xticklabels(), visible=False)
示例#7
0
			print i
except:
	pass

#debugging plot below, make sure parameters match the ones actually used
gate = DmGateway()
#gate = StaticGateway("staticDataSet.json")
ps = Parser()

dset = ps.parse(time_series)

series = ts.time_series(dset[1].getMaskedArray(),
						start_date=ts.Date(freq='year', year=1, month=1))
#print series.count

fig = tplot.tsfigure()
# 111 = width, height, subplots
fsp = fig.add_tsplot(111)
fsp.tsplot(series, '-')
np.seterr(invalid='raise')
try:
	avg = mov_average(series, 20)
	std = mov_std(series, 20)
except Exception as error:
	print error
	traceback.print_exc()
print series
print avg
print std
lowerlim = avg+std*2
upperlim = avg-std*2