基础代码

import numpy , matplotlib.pyplot


numpy 部分

data = np.array([ [ , ] , [ , ] , [ , ] ])

array 里面是数组,数组是个【】,然后里面放 n个,1行 * 多列的数组

data.shape

shape 表示数组大小,(行数,列数)

拆解数组:
data [ : 2 ] 显示数组第1,2个元素

x1 = data [ : , 0 ]

x1 表示列表,1行 * 多列第 1 列 元素,

x2 = x1 . reshape ( 行数 , 列数 )

x2 表示将 列表 重组成 行数 * 列数 的数组

特例:x2 = x1 . reshape ( -1, 列数 )

规定的列数,行数自适应


matplotlib 部分

plt.scatter ( x , y , color = ’ red ’ )

描点画图,红色点

plt.xlabel ( ’ x坐标的名字 ’ )
plt.ylabel ( ’ y坐标的名字 ’ )

plt.show( )

显示出来,没这句没有图


整合代码

import numpy as np #科学计算
import matplotlib.pyplot as plt #画图
data = np.array([[152, 51], [156, 53], [160, 54], [164, 55],[168, 57], [172, 60], [176, 62], [180, 65],[184, 69], [188, 72]])
x = data[:,0].reshape(-1,1)
y = data[:,1]
plt.scatter(x,y,color=“black”)
plt.xlabel(‘xx’)
plt.ylabel(‘yy’)
plt.show()

在这里插入图片描述

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值