记录一下关于plt.scatter(X[y==1,0], X[y==1,1])的解读

from sklearn.datasets import make_moons
import matplotlib.pyplot as plt

X, y = make_moons(n_samples=50, random_state=123)
print(X,y)
plt.scatter(X[y==0,0], X[y==0,1], color='red', marker='^', alpha=0.5)
plt.scatter(X[y==1,0], X[y==1,1], color='blue', marker='o', alpha=0.5)
plt.show()

在此,数组X将会生成一个50行2列的二维数组

[[ 2.58819045e-01  9.65925826e-01]
 [-1.30526192e-01  9.91444861e-01]
 [ 2.06646660e-01 -1.08761429e-01]
 [ 1.92387953e+00  1.17316568e-01]
 [-7.07106781e-01  7.07106781e-01]

 [.......................................................]

 [ 1.86602540e+00 -3.33066907e-16]]

y对应的是这些数据的分类结果[0 0 1 1 0 0 1 0 1 0 0 1。。。。。。0 1]。

也就是坐标点[ 2.58819045e-01  9.65925826e-01]的对应的编号为0

 [-1.30526192e-01  9.91444861e-01]的对应的编号为0

 [ 2.06646660e-01 -1.08761429e-01]的对应的编号为1

所以X[y==0,:],是所有编号为0的坐标点,X[y==0,0],是所有编号为0的X坐标,也就是2.58819045e-01、-1.30526192e-01、-7.07106781e-01。X[y==0,1]是所有编号为0的Y坐标,也就是9.65925826e-01、9.91444861e-01、7.07106781e-01

 

  • 19
    点赞
  • 38
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
import numpy as np import matplotlib.pyplot as plt import sympy from scipy.interpolate import interp1d gamma = 1.2 R = 8.314 T0 = 500 Q = 50 * R * T0 a0 = np.sqrt(gamma * R * T0) M0 = 6.216 P_P0 = sympy.symbols('P_P0') num = 81 x0 = np.linspace(0,1,num) t_t0 = np.linspace(0,15,num) x = x0[1:] T_T0 = t_t0[1:] h0 = [] h1 = []#创建拉姆达为1的空数组 r = [] t = [] c = [] s = [] i = 0 for V_V0 in x: n1 = sympy.solve(1 / (gamma-1) * (P_P0 * V_V0 - 1) - 0.5 * (P_P0 + 1) * (1 - V_V0)- gamma * 0 * Q / a0 ** 2,P_P0)#lamuda=0的Hugoniot曲线方程 n2 = sympy.solve(1 / (gamma-1) * (P_P0 * V_V0 - 1) - 0.5 * (P_P0 + 1) * (1 - V_V0)- gamma * 1 * Q / a0 ** 2,P_P0)#lamuda=1的Hugoniot曲线方程 n3 = sympy.solve(-1 * P_P0 + 1 - gamma * M0 ** 2 * (V_V0 - 1),P_P0)#Reyleigh曲线方程 n4 = 12.014556 / V_V0#等温线 n5 = sympy.solve((P_P0 - 1 / (gamma+1) )* (V_V0-gamma / (gamma + 1)) - gamma / ((gamma + 1) ** 2),P_P0)#声速线 n6 = 10.6677 / np.power(V_V0,1.2)#等熵线 h0.append(n1) h1.append(n2) r.append(n3) t.append(n4) c.append(n5) s.append(n6) i = i+1 h0 = np.array(h0) h1 = np.array(h1) r = np.array(r) t = np.array(t) c = np.array(c) s = np.array(s) plt.plot(x,r,label='Rayleigh') plt.plot(x,t,color='purple',label='isothermal') plt.plot(x,s,color='skyblue',label='isentropic') a = np.where(h0 < 0) b = np.where(c < 0) h0 = np.delete(h0,np.where(h0 < 0)[0],axis = 0)#去除解小于0的值 h1 = np.delete(h1,np.where(h1 < 0)[0],axis = 0)#去除解小于0的值 c = np.delete(c,np.where(c < 0)[0],axis = 0)#去除解小于0的值 x0 = np.delete(x,a,axis = 0)#对应去除x轴上错误值的坐标 x1 = np.delete(x,b,axis = 0) plt.plot(x0,h0,label='Hugoniot(lambda=0)') plt.plot(x0,h1,label='Hugoniot(lambda=1)') plt.plot(x1,c,color='yellow',label='soniclocus') plt.ylim((0,50)) plt.legend() # 显示图例 plt.xlabel('V/V0') plt.ylabel('P/P0') f1 = interp1d(x1, c.T, kind='cubic') f2 = interp1d(x,r.T,kind='cubic') f3 = interp1d(x, t.T, kind='cubic') epsilon = 0.0001 x0 = 0.56 y0 = f1(x0) - f2(x0) while abs(y0) > epsilon: df = (f1(x0 + epsilon) - f2(x0 + epsilon) - y0) / epsilon x0 -= y0 / df y0 = f1(x0) - f2(x0) plt.scatter(x0, y0, 50, color ='red') plt.show()
06-08
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值