import numpy as np import pandas as pd from pandas import Series,DataFrame import matplotlib.pyplot as plt
手动绘制散点图的背景颜色
In [11]:
x = [1,2,3] y = [6,7,8] plt.scatter(x,y)
Out[11]:
- 设定一组x,y
In [12]:
x = np.linspace(1,3,num=100) y = np.linspace(6,8,num=100)
In [14]:
# 返回一个网格矩阵
xx,yy = np.meshgrid(x,y)
In [15]:
xx.shape
Out[15]:
In [18]:
# 生成两列坐标点
xy = np.c_[xx.reshape(10000,),yy.reshape(10000,)] xy
Out[18]:
In [19]:
# 取第一列
xy[:,0]
Out[19]:
In [21]:
# xy中第一列为scatter中第一个参数,第二列为scatter中第二个参数
plt.scatter(xy[:,0],xy[:,1]) plt.scatter([1,2,3],[6,7,8])
Out[21]:
meshgrid举例
a = np.array([1,2,3])
b = np.array([4,5,6])
In [8]:
aa,bb = np.meshgrid(a,b)
In [9]:
display(aa,bb)
In [12]:
display(aa.reshape(9,),bb.reshape(9,))
In [13]
A,B = aa.reshape(9,),bb.reshape(9,)
In [14]:
np.c_[A,B]
Out[14]: