This repository has been archived on 2024-01-06. You can view files and clone it, but cannot push or open issues or pull requests.
justhomework/AIandML/e1_python_basics/e1.2_matplotlib.ipynb

123 lines
54 KiB
Text
Raw Normal View History

2022-09-21 03:18:09 +00:00
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# 人工智能与机器学习-实验1"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Part.III Matplotlib绘图练习\n",
"\n",
"|学号 |姓名 |\n",
"|----------|--------|\n",
2023-06-18 07:57:59 +00:00
"|2020114490|江一和|\n",
2022-09-23 12:00:14 +00:00
"|2020113874|何一涛|"
2022-09-21 03:18:09 +00:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 1. 曲线\n",
"\n",
"* 用蓝线绘制函数$𝑓(𝑥) = 𝑥^22𝑥+3$的图表,并在坐标(1,2)位置处标上一个红色的点\n"
]
},
{
"cell_type": "code",
2022-10-12 01:30:07 +00:00
"execution_count": 1,
2022-09-21 03:18:09 +00:00
"metadata": {},
2022-09-21 03:36:32 +00:00
"outputs": [
{
"data": {
2022-10-12 01:30:07 +00:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAiMAAAGdCAYAAADAAnMpAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjYuMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy89olMNAAAACXBIWXMAAA9hAAAPYQGoP6dpAABJo0lEQVR4nO3dfXzNdePH8ddhbMImYnOzJDTkJkKmX1KUoi7qiqwJXSiiqKsb67quUq6akkoppDK1NHShkptESCi3NYqIhrKVYgcxbN/fH5/Lrlbb7Gxn+5yb9/PxOI/a8T3nvL+O7bz3/X6+n4/LcRwHEREREUvK2Q4gIiIiwU1lRERERKxSGRERERGrVEZERETEKpURERERsUplRERERKxSGRERERGrVEZERETEqhDbAYoiJyeHH3/8kapVq+JyuWzHERERkSJwHIcjR45Qp04dypUr+PiHX5SRH3/8kejoaNsxREREpBj27dtHvXr1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kbL0n//ALbfA9u0QE2M7zZ+VyQBWMW30s89gzx7bSUREJNi8/bZZodcXi4gnVEZKqFcvqFxZK/mKiEjZ8tcVevOjMlJClStrJV8RESl7/rpCb35URrygXz9zvm7zZttJREQkWCQnQ9eu/rdCb35URryga1eIjIQ337SdREREgsGePWZ+kUA4RQMqI14REmL+Qbz9Npw8aTuNiIgEujffhCpV4OabbSfxDpURLxk
2022-09-21 03:36:32 +00:00
"text/plain": [
"<Figure size 640x480 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"x = np.linspace(-1, 3, 50)\n",
"y = x**2 - 2*x + 3\n",
"plt.plot(x, y, color='blue', linewidth=1.0)\n",
"plt.scatter(1, 2, color='red')\n",
"plt.show()\n"
]
2022-09-21 03:18:09 +00:00
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 2. x-y图\n",
"\n",
"* 使用`np.linspace()`函数生成$t\\in [0, 2\\pi]$。\n",
"* 给定$𝑥=16*sin(𝑡)^3$和$𝑦=13*cos(𝑡)5*cos(2𝑡)2*cos(3𝑡)cos(4𝑡)$画出x-y图表\n",
"* 并给图标添加一个题目Heart"
]
},
{
"cell_type": "code",
2022-10-12 01:30:07 +00:00
"execution_count": 2,
2022-09-21 03:18:09 +00:00
"metadata": {},
2022-09-21 03:36:32 +00:00
"outputs": [
{
"data": {
2022-10-12 01:30:07 +00:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAioAAAGzCAYAAAABsTylAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjYuMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy89olMNAAAACXBIWXMAAA9hAAAPYQGoP6dpAABQAklEQVR4nO3dd3jN5/sH8PdJREhkGCFCxN7ETOxRalat2iO0xjeomi1tzZZQRUu1qmq0NkVpzRKUxCiiqnYRNWJVEkHm5/fH/RNNJbLOOc/nnPN+Xde5IkPydu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CCBcDq1bJAtmlTeZDs3JkjJ6b2+DGwZYsULTt2SK+Kt94ChgyREReyXufOAfPmyfb3p0/lxcCbbwKvv85dY6b28CGwYQOwYoWstcubF+jbFxg8WBblklGxUKGsiY2V0ZMFC4CQEGmsNnAg0K+fDDeT+V25Anz1FbB4sTyQtmkDvP22PIHxVbV10DRZbP3ZZ1KYFiokRelbbwFFiqhOZ5suXQK++UZGtO7elR2Lw4bJehb2RzKKjD5/2+hycHrBP/8A06dLg6deveSV24YN0lxp8mQWKSqVKAF88okcIbB4sexmaNVKhv83bHjetIssT3y8PBFWqiT/pxERMop27RowcSKLFJVKlwZmzpTdQmvWyO6pbt3k43PnytQcmQULFVt3/TowerTsHJg6FWjfXhqY7d0rUzzPWmGTek5OMgVw4oT8/+TPL+uEKlWSJ7d
2022-09-21 03:36:32 +00:00
"text/plain": [
"<Figure size 640x480 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"t = np.linspace(0, 2*np.pi, 1000)\n",
"x = 16*np.sin(t)**3\n",
"y = 13*np.cos(t) - 5*np.cos(2*t) - 2*np.cos(3*t) - np.cos(4*t)\n",
"plt.plot(x, y, color='red', linewidth=1.0)\n",
"plt.title('Heart')\n",
"plt.show()"
]
2022-09-21 03:18:09 +00:00
}
],
"metadata": {
"kernelspec": {
2022-10-12 01:30:07 +00:00
"display_name": "Python 3 (ipykernel)",
2022-09-21 03:18:09 +00:00
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
2022-09-21 03:36:32 +00:00
"version": "3.10.7"
},
"vscode": {
"interpreter": {
"hash": "1f0d395e06aa83586067b19165efc9b683889967164248deef4bbf1fa27cfb00"
}
2022-09-21 03:18:09 +00:00
}
},
"nbformat": 4,
"nbformat_minor": 2
}