深度学习入门:基于Python的理论与实现¶
Chap1: Python入门¶
Matplotlib的使用¶
Sin函数曲线¶
In [1]:
Copied!
import numpy as np
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.pyplot as plt
In [2]:
Copied!
x = np.arange(0, 6, 0.1) # 以0.1为单位,生成0到6的数据
y = np.sin(x)
x = np.arange(0, 6, 0.1) # 以0.1为单位,生成0到6的数据
y = np.sin(x)
Sin/Cos函数曲线¶
In [4]:
Copied!
x = np.arange(0, 6, 0.1)
y1 = np.sin(x)
y2 = np.cos(x)
x = np.arange(0, 6, 0.1)
y1 = np.sin(x)
y2 = np.cos(x)
In [5]:
Copied!
plt.plot(x, y1, label="sin")
plt.plot(x, y2, linestyle="--", label="cos") # 虚线
plt.xlabel("x") # x轴标签
plt.ylabel("y") # y轴标签
plt.title("sin & cos") # 标题
plt.legend()
plt.show()
plt.plot(x, y1, label="sin")
plt.plot(x, y2, linestyle="--", label="cos") # 虚线
plt.xlabel("x") # x轴标签
plt.ylabel("y") # y轴标签
plt.title("sin & cos") # 标题
plt.legend()
plt.show()
显示图片¶
In [6]:
Copied!
from matplotlib.image import imread
from PIL import Image
from io import BytesIO
import requests
from matplotlib.image import imread
from PIL import Image
from io import BytesIO
import requests
In [7]:
Copied!
# imread("local_image_file")
url = "https://static.cyub.vip/images/202410/lena.png"
response = requests.get(url)
img = Image.open(BytesIO(response.content))
plt.imshow(img)
plt.show()
# imread("local_image_file")
url = "https://static.cyub.vip/images/202410/lena.png"
response = requests.get(url)
img = Image.open(BytesIO(response.content))
plt.imshow(img)
plt.show()