In [1]:
f=logspace(0,4,1000)

C=1e-6
R=3e3

au=(1./(1j*2*pi*f*C)) / (R+(1./(1j*2*pi*f*C)))

fig=figure()
ax=subplot(111)
semilogx(f,20*log10(abs(au)))
grid(True,'both')
text(200,-10,'-20dB/dek',size=20,rotation=-50)
figtext(0.8,0.05,'OSA X')
figtext(0.05,0.8, 'OSA Y',rotation=90)

l = plt.axvline(x= 1/(2*pi*R*C), ymax=0.95, linestyle='--', linewidth=2, color='#ee55aa')
l = plt.axhline(y=-3, xmin=0, xmax=0.8, linestyle='-.', linewidth=2, color='g')
t=text(1/(2*pi*R*C),-55,'$f_m$',size=16)

#print ax.get_yticklabels()

# přidám si speciální místa na osu y
yticks(list(yticks()[0]) + [-12,-25])
print yticks()[0]
# přidám ještě speciálnější popisek
yticks(list(yticks()[0]) + [-3], list(yticks()[0]) + ['pokles o -3dB'] )
# yticks()[0] jsou tiky
# yticks()[1] jsou popisky -- objekty typy Text; takže volám Text.set_color() na poslední přidaný prvek
yticks()[1][-1].set_color('r')

# ... nebo jíný způsob -- chová se tovhu jinak
#ax.set_yticks(ax.get_yticks()+[-3] )


# do grafu přidám další graf
ax=fig.add_axes([0.7,0.4,0.3,.4], axisbg='yellow', alpha=0.1)
ax.set_yticks([-3])
ax.set_yticklabels(['-3'])
ax.grid()
ax.plot(f,20*log10(abs(au)))


[-50. -40. -30. -20. -10.   0. -12. -25.]
Out[1]:
[<matplotlib.lines.Line2D at 0x2ec34d0>]

Graf v grafu


In [2]:
import numpy as np
from matplotlib import pyplot as plt
from scipy import randn, convolve

#data
t = np.arange(0.0, 20.0, 0.001)
r = np.exp(-t[:1000]/0.05)     
x = randn(len(t))
s = convolve(x,r)[:len(x)]*0.001
theta = 2 * np.pi * t
#
fig = plt.figure(figsize=(7, 6))
#main
plt.plot(t, s)
plt.axis([0, 1, np.amin(s), 2.5*np.amax(s)])
plt.xlabel('xlabel')
plt.ylabel('ylabel')
#polar
ax = fig.add_axes([0.2, 0.47, 0.30, 0.40], polar=True, axisbg='yellow')
ax.plot(theta, t, color='blue', lw=3)
ax.set_rmax(1.0)
plt.grid(True)

plt.show()



In [3]:
import matplotlib.pyplot as plt
import matplotlib.patches as mpp
fig = plt.figure(figsize=(7,4))
ax=fig.add_subplot(111)
ax.axis([520,580, 0,0.2])
a = plt.arrow(550,0.06,15,0.1, width=0.01, head_length=1.)
ax.add_patch(a)
b = mpp.YAArrow(fig, (555,0.16), (540,0.06), width=0.01, headwidth=0.03)
ax.add_patch(b)
c = mpp.FancyArrowPatch((530,0.06), (545,0.16), arrowstyle='<|-|>', lw=2, mutation_scale=50, color='k')
ax.add_patch(c)
plt.show()



In [1]:
import matplotlib.patches as mpp

ax=subplot(111)
axis([0,300, 0,400])
grid(True,'both')

# linestyle or ls 	[‘solid’ | ‘dashed’ | ‘dashdot’ | ‘dotted’]
c = mpp.FancyArrowPatch((50,300), (150,200), arrowstyle='<|-|>', 
                        lw=2, linestyle='dotted', mutation_scale=20,
                        color='green', label='popisek', alpha=0.5)
ax.add_patch(c)
legend()
text(90,240,'BB',size=32)

# i anntate použíévá class matplotlib.patches.FancyArrowPatch

annotate('Ahoj', xy=(200,150),size=20, xytext=(250,200),
          arrowprops=dict(arrowstyle="->",
                          connectionstyle="arc3,rad=0.2",
                          fc="w") 
         )


annotate('Q', xy=(100,100),size=20, xytext=(150,100),
          arrowprops=dict(arrowstyle="->",connectionstyle="arc3,rad=0", ), 
         )
annotate('B', xy=(200,100),size=20, xytext=(150,100),
          arrowprops=dict(arrowstyle="->",connectionstyle='bar') ,
          horizontalalignment='right', verticalalignment='top' 
         )

####################
# Bubliny
bbox_props = dict(boxstyle="rarrow,pad=0.3", fc="cyan", ec="b", lw=2)
t = ax.text(150,300, "Direction", ha="center", va="center", rotation=45,
            size=15,
            bbox=bbox_props)

bbox_props = dict(boxstyle="round,pad=0.3", fc=".9", ec="b", lw=2)
t=annotate(u'Carsonův odhad', xy=(150,120),size=16, xytext=(40,20),bbox=bbox_props,
          arrowprops=dict(arrowstyle="->", connectionstyle="arc3,rad=-1.5", fc="w") 
         )



In [4]:
ax=subplot(111)

X = np.linspace(-np.pi, np.pi, 256,endpoint=True)
C,S = np.cos(X), np.sin(X)

plot(X, C, color="blue", linewidth=2.5, linestyle="-", label="cosine")
plot(X, S, color="red", linewidth=2.5, linestyle="-",  label="sine")


#############Přesnun popisků na "klasické" místo
#ax = gca()
ax.spines['right'].set_color('none')
ax.spines['top'].set_color('none')
ax.xaxis.set_ticks_position('bottom')
ax.spines['bottom'].set_position(('data',0))
ax.yaxis.set_ticks_position('left')
ax.spines['left'].set_position(('data',0))


############# Popisky os
xlim(X.min()*1.1, X.max()*1.1)
xticks([-np.pi, -np.pi/2, 0, np.pi/2, np.pi],
       [r'$-\pi$', r'$-\pi/2$', r'$0$', r'$+\pi/2$', r'$+\pi$'])

ylim(C.min()*1.1,C.max()*1.1)
yticks([-1, +1],
       [r'$-1$', r'$+1$'])

t = 2*np.pi/3


## modrá čárkovaná čára
plot([t,t],[0,np.cos(t)],
     color ='blue',  linewidth=1.5, linestyle="--")
## modrý puntík
scatter([t,],[np.cos(t),], 50, color ='blue')
## popisek k modrému puntíku
annotate(r'$\sin(\frac{2\pi}{3})=\frac{\sqrt{3}}{2}$', xy=(t, np.sin(t)),  xycoords='data',
         xytext=(+10, +30), textcoords='offset points', fontsize=16,
         arrowprops=dict(arrowstyle="->", connectionstyle="arc3,rad=.2"))

### červená čárkovaná čára
plot([t,t],[0,np.sin(t)],
          color ='red',  linewidth=1.5, linestyle="--")
## červený puntík
scatter([t,],[np.sin(t),], 50, color ='red')
## červený popisek
annotate(r'$\cos(\frac{2\pi}{3})=-\frac{1}{2}$', xy=(t, np.cos(t)),  xycoords='data',
         xytext=(-90, -50), textcoords='offset points', fontsize=16,
         arrowprops=dict(arrowstyle="->", connectionstyle="arc3,rad=.2"))

legend(loc='upper left')

# savefig("../figures/exercice_9.png",dpi=72)
#show()


Out[4]:
<matplotlib.legend.Legend at 0x3fc5590>

In [ ]: