import matplotlib.patches as mpp
import scipy.interpolate as interpol
#####################################
al=0.5
figure(figsize=(10,7))
ax=subplot(111)
grid(0)
xlim([0,1])
ylim([-3.5,3.5])
axhline(y=3, xmin=0, xmax=1, linestyle='-.', linewidth=2, color='r', alpha=al,label=ur'kvantovací hladina')
axhline(y=2, xmin=0, xmax=1, linestyle='-.', linewidth=2, color='r', alpha=al)
axhline(y=1, xmin=0, xmax=1, linestyle='-.', linewidth=2, color='r', alpha=al)
axhline(y=0, xmin=0, xmax=1, linestyle='-.', linewidth=2, color='r', alpha=al)
axhline(y=-1, xmin=0, xmax=1, linestyle='-.', linewidth=2, color='r', alpha=al)
axhline(y=-2, xmin=0, xmax=1, linestyle='-.', linewidth=2, color='r', alpha=al)
axhline(y=-3, xmin=0, xmax=1, linestyle='-.', linewidth=2, color='r', alpha=al)
axhline(y=2.5, xmin=0, xmax=1, linestyle=':', linewidth=2, color='g', alpha=al,label=ur'rozhodovací hladina')
axhline(y=1.5, xmin=0, xmax=1, linestyle=':', linewidth=2, color='g', alpha=al,)
axhline(y=0.5, xmin=0, xmax=1, linestyle=':', linewidth=2, color='g', alpha=al,)
axhline(y=-0.5, xmin=0, xmax=1, linestyle=':', linewidth=2, color='g', alpha=al,)
axhline(y=-1.5, xmin=0, xmax=1, linestyle=':', linewidth=2, color='g', alpha=al,)
axhline(y=-2.5, xmin=0, xmax=1, linestyle=':', linewidth=2, color='g', alpha=al,)
t=arange(0.02,1,0.08)
len(t)
u=[1,2,2,3,1,2,1,0,-1,-2,-1,-3,-2]
len(u)
stem(t,u, linefmt='b', markerfmt='o', basefmt='|',)
tt=linspace(0.01,0.99,1000)
funkce=interpol.UnivariateSpline(t,u,s=0.5)
uu=funkce(tt)
plot(tt,uu,'k-',label=u'původní signál')
plot(t,funkce(t),'k.')
annotate(u'',size=16, xy=(t[3],3),xytext=(t[3],funkce(t[3])),
arrowprops=dict(arrowstyle="->", color='m', connectionstyle="arc3,rad=1.5", fc="w") )
annotate(u'',size=16, xy=(t[4],1),xytext=(t[4],funkce(t[4])),
arrowprops=dict(arrowstyle="->", color='m', connectionstyle="arc3,rad=1.5", fc="w") )
annotate(u'',size=16, xy=(t[5],2),xytext=(t[5],funkce(t[5])),
arrowprops=dict(arrowstyle="->", color='m', connectionstyle="arc3,rad=1.5", fc="w") )
xlabel(r't\,[s] $\rightarrow$', x=0.9)
ylabel('$\mathrm u$\,[V] $\uparrow$', y=0.9, rotation=0)
legend()