数据分析笔记Matplotlib(8)-图中图

import matplotlib.pyplot as plt

# 窗口
fig = plt.figure()

x = [1, 2, 3, 4, 5, 6, 7]
y = [1, 3, 4, 2, 5, 8, 6]

#大图左下角的位置以及宽高的百分比
left, bottom, width, height = 0.1, 0.1, 0.8, 0.8

ax1 = fig.add_axes([left, bottom, width, height])#大图添加入窗口
ax1.plot(x, y, 'r') #显示数据对应的图像,颜色为红色
ax1.set_xlabel('x')#x坐标名称
ax1.set_ylabel('y')#y坐标名称
ax1.set_title('title')#图像名称

#第一个小图的位置以及宽高的百分比
left, bottom, width, height = 0.2, 0.6, 0.25, 0.25
ax2 = fig.add_axes([left, bottom, width, height])
ax2.plot(y, x, 'b')
ax2.set_xlabel('x')
ax2.set_ylabel('y')
ax2.set_title('内置图1')

#第二个小图
plt.axes([0.6, 0.2, 0.25, 0.25]) #直接使用坐标信息
plt.plot(y[::-1], x, 'g') # 对y进行逆序处理
plt.xlabel('x')
plt.ylabel('y')
plt.title('内置图2')

plt.show()

数据分析笔记Matplotlib(8)-图中图_第1张图片

你可能感兴趣的:(Python数据分析,Python数据分析,Matplotlib,图中图)