Python学习之路_matplotlib

1. Plotting a function

代码

from numpy import *
import matplotlib.pyplot as plt

x=linspace(0,2)
y = sin(x-2)*sin(x-2)*exp(-(x**2))
plt.plot(x,y,)
plt.title('My_plot')
plt.xlabel('X')
plt.ylabel('Y')
plt.show()

结果

这里写图片描述

2. Data

这里写图片描述

代码

from numpy import *
import matplotlib.pyplot as plt

X = random.random((20, 10))
b = random.randint(0, 10, size=(10, 1))
z = random.normal(size=(20, 1))
y = X.dot(b) + z
b1 = linalg.lstsq(X, y)[0]
plt.xlabel('X')
plt.ylabel('Y')
plt.scatter(range(10), list(b1.T), marker='o')
plt.scatter(range(10), list(b.T), marker='*')
plt.legend(['True coefficients', 'Estimated coefficients'])
plt.show()  

结果

这里写图片描述

3. Histogram and density estimation

这里写图片描述

代码

import numpy as np
import matplotlib.pyplot as plt
import seaborn as sea

x = np.random.randn(10000)
sea.distplot(x, bins=25, kde=True, rug=False)
plt.show()

结果

这里写图片描述

猜你喜欢

转载自blog.csdn.net/manjiang8743/article/details/80494625