天天看点

4.Matplotlib绘图--散点图

散点图:是指在​​回归分析​​​中,数据点在直角坐标系平面上的​​分布图​​​,散点图表示因变量随​​自变量​​​而​​变化​​的大致趋势,据此可以选择合适的函数​​对数​​​据点进行​​拟合​​。

1.画点:scatter

import matplotlib.pyplot as plt
import numpy as np
#画点
plt.scatter(np.arange(5),np.arange(5))
plt.show()      
4.Matplotlib绘图--散点图

2.散点图

x=np.random.normal(0,1,500)
y=np.random.normal(0,1,500)
plt.scatter(x,y,s=50,c='r',alpha=0.5)
plt.xlim((-2,2))
plt.ylim((-2,2))
#去掉X/Y轴默认坐标
plt.xticks(())
plt.yticks(())
plt.show()      

3.改变散点形状和颜色:这个案例来自matplotlib官网

import matplotlib.pyplot as plt
import numpy as np
# Fixing random state for reproducibility
np.random.seed(19680801)
N = 100
r0 = 0.6
x = 0.9 * np.random.rand(N)
y = 0.9 * np.random.rand(N)
area = (20 * np.random.rand(N))**2  # 0 to 10 point radii
c = np.sqrt(area)
r = np.sqrt(x * x + y * y)
area1 = np.ma.masked_where(r < r0, area)
area2 = np.ma.masked_where(r >= r0, area)
plt.scatter(x, y, s=area1, marker='^', c=c)
plt.scatter(x, y, s=area2, marker='o', c=c)

plt.show()      
# Show the boundary between the regions:
theta = np.arange(0, np.pi / 2, 0.01)
plt.plot(r0 * np.cos(theta), r0 * np.sin(theta))
plt.show()