数据处理-Matplotlib 绘图展示
    		       		warning:
    		            这篇文章距离上次修改已过443天,其中的内容可能已经有所变动。
    		        
        		                
                
import matplotlib.pyplot as plt
import numpy as np
 
# 生成模拟数据
x = np.linspace(0, 10, 1000)
y = np.sin(x)
z = np.cos(x)
 
# 创建图像和轴
fig, ax = plt.subplots()
 
# 绘制曲线
ax.plot(x, y, label='sin(x)', color='blue', linewidth=2)
ax.plot(x, z, label='cos(x)', color='red', linewidth=2)
 
# 设置标题和坐标轴标签
ax.set_title('sin(x) and cos(x)')
ax.set_xlabel('x')
ax.set_ylabel('y')
 
# 显示图例
ax.legend()
 
# 显示网格
ax.grid()
 
# 展示图像
plt.show()这段代码使用Matplotlib库生成了一个二维函数sin(x)和cos(x)的图像,展示了如何创建图像、绘制线条、设置标题、坐标轴标签、显示图例和网格。最后,使用plt.show()展示了生成的图像。
评论已关闭