Exercise11-Matplotlib

This blog covers three exercises on using Matplotlib in Python. Exercise 11.1 demonstrates plotting a function using numpy.arange for dense points. Exercise 11.2 involves plotting functions with least-squares solutions using numpy.linalg.lstsq. Exercise 11.3 explores histogram and density estimation with scipy.stats.gaussian_kde. Each exercise includes analysis, relevant explanations, code implementation, and corresponding images." 132851840,10220647,AutoSAR入门:理解基础与核心概念,"['autosar', '开发语言', '软件架构']
摘要由CSDN通过智能技术生成

Exercise 11.1: Plotting a function

11.1

分析:

要绘制这样的函数图像,用点来描绘,选择给定区间较密集的点(用numpy.arange实现其x坐标在该区域的等距选取),y用给定的表达式给出,使用plot绘制即可。

相关说明:

  1. pylab将pyplot与numpy合并为一个命名空间。这对于交互式工作很方便,但是对于编程来说,建议将名称空间分开。
    例:画 y = sin x 图像(我由此找到了解题的方法)
import numpy as np
import matplotlib.pyplot as plt

x = np.arange(0, 5, 0.1);
y = np.sin(x)
plt.plot(x, y)
plt.show()

2 . arrange()函数
函数说明:arange([start,] stop[, step,], dtype=None)根据start与stop指定的范围以及step设定的步长,生成一个 ndarray。 dtype : dtype
The type of the output array. If dtype is not given, infer the data
type from the other input arguments.
ow、high、size三个参数。默认high是None,如果只有low,那范围就是[0,low)。如果有high,范围就是[low,high)。
一些例子:

np.random.randint(2, size=10)
array([1, 0, 0, 0, 1, 1, 0, 0, 1, 0])

 np.random.randint(1, size=10)
array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0])

 np.random.randint(5, size=(2, 4))
array([[4, 0, 2, 1],
       [3, 2, 2, 0]])

代码实现

x = np.arange(0,
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值