参考文档:https://www.zhihu.com/question/51745620
关于方法add_axes 和 add_subplot 创建axes画图区域的区别
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
x = np.random.randint(1, 10, 3)
y = np.arange(0, 3, 1)
# 创建一个画板的意思
fg = plt.figure() # type:plt.Figure
# 在画板上添加一个可绘画的区域【坐标轴】
ax = fg.add_subplot(1, 1, 1) # type:plt.Axes
# 接下来一系列操作都是基于axes对象中操作!
ax.locator_params(axis="x", nbins=2, tight=True)
a1, = ax.plot(y, x, "r.--", label="line", )
a2, = ax.plot(y + 1, "g.--", label="line2")
ax.legend((a1, a2), ("line", "line2"))
fg.show()
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
x = np.arange(1, 12, 4)
y = np.arange(1, 4, 1)
fg = plt.figure() # type:plt.Figure
# 这里是[left, bottom, width, height] 是百分比小数【相对figure】
ax = fg.add_axes([0, 0, 1, 1])
ax1 = fg.add_axes([0.1, 0.1, 0.5, 0.5])
ax.plot(x, y)
ax1.plot(x, y)
fg.show()