Matplotlib库学习

Matplotlib数据可视化

绘制折线图 pyplot

import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(0, 10, 100)
siny = np.sin(x)
cosy = np.cos(x)
#---绘图---
plt.plot(x, siny, label="sin x")
plt.plot(x, cosy, color="red", linestyle="--", label="cos x")
#---轴的范围---
# plt.xlim(-5, 15) 
# plt.ylim(-1.5, 1.5)
plt.axis([-5, 15, -1.5, 1.5])
#---轴的标签---
plt.xlabel("x_axis")
plt.ylabel("y_axis")
#---渲染出曲线label属性的内容---
plt.legend()  
plt.title("Title!!!!")
plt.show()

Matplotlib库学习_第1张图片

绘制散点图

plt.scatter(x, siny, label="sin x")
plt.scatter(x, cosy, color="red", label="cos x")
plt.axis([-5, 15, -1.5, 1.5])
plt.legend()
plt.show()

Matplotlib库学习_第2张图片

# 二维正态分布
x = np.random.normal(0, 1, 10000)
y = np.random.normal(0, 1, 10000)

plt.scatter(x, y, alpha=0.1)  #alpha:透明度
plt.show()

Matplotlib库学习_第3张图片

你可能感兴趣的:(AI)