# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# # Matplotlib Basic Operation and Plot

# ## Matplotlib api table
# ![matplotlib_api](./images/matplotlib_api.png)

import matplotlib.pyplot as plt

# 绘制直线, x,y的坐标
plt.plot([0, 2], [1, 4])
plt.show()

# 绘制折线
X = [1, 2, 3, 4, 5]
Y = [1, 4, 9, 16, 25]
plt.plot(X, Y)
plt.show()

# ## 设置标签和文字粗细

# +
datas = [1, 2, 3, 4, 5]
squares = [1, 4, 9, 16, 25]
plot.plot(datas, squares, linewidth=5) # 设置线的宽度

# 设置图标标题，并在坐标轴上添加标签
plt.title('Numbers', fontsize=24)
plt.xlabel('datas', fontsize=14)
plt.ylabel('squares', fontsize=14)
plt.show()
# -

# ## 绘制一元二次方程

x = range(-100, 100)
y = [i ** 2 for i in x]
plt.plot(x, y)
plt.show()

# ## 绘制正弦余弦曲线

import numpy as np

## 生成0-10之间 100个等差数
x = np.linspace(0, 10, 100)
sin_y = np.sin(x)

plt.plot(x, sin_y)
plt.show()

# ### 绘制余弦

cos_y = np.cos(x)

plt.plot(x, cos_y)
plt.plot(x, sin_y)
plt.show()

# ## subplot的使用

# +
# 对画布进行分区
plt.subplot(2, 2, 1)
# 修改x, y轴的坐标
plt.xlim(-5, 20)
plt.ylim(-2, 2)
plt.plot(x, sin_y)

plt.subplot(2, 2, 3)
plt.plot(x, cos_y)
plt.show()
# -



StarcoderdataJupyterScriptsDedupFiltered