twn39 / code

:memo: 代码笔记,通过 issue 的方式记录日常遇到的问题和学习笔记
13 stars 1 forks source link

Matolotlib绘图 #18

Open twn39 opened 9 years ago

twn39 commented 9 years ago

以下示例使用pylabseaborn:

%pylab inline
import seaborn as sns
twn39 commented 9 years ago

线图:

x = linspace(-5,5,200)
plot(x,sin(x),label='$sin(x)$')
plot(x, cos(x), label='$cos(x)$')
plot(x, sin(x)*cos(x), '--',label='$sin(x)cos(x)$')
title('Matplotlib')
xlabel('$x$')
ylabel('$f(x)$')
text(-0.5, sin(-0.5), '$\leftarrow (-0.5, sin(-0.5))$')
legend()

index

twn39 commented 9 years ago

散点图:

a = linspace(-5,5,200)
b = 3*x+2
bn = b + normal(5, 3.5,size(b))   # 产生数据
scatter(a, bn, color='g', alpha=0.4, s=50)

index

twn39 commented 9 years ago

直方图:

bar = normal(2, 1.5, 100)
hist(bar, label='Normal')
legend()

hist

twn39 commented 9 years ago

箱形图:

box = normal(2, 1.5, 100)
sns.boxplot(box)

box