使用 Qt
作为 Matplotlib 后端:
Matplotlib 也可以使用 Qt
作为后端,然后通过 Qt
窗口的方法来控制窗口位置。以下是一个示例:(其它也有使用使用 wxPython
作为 Matplotlib 后端,使用 tkinter
作为 Matplotlib 后端)
import matplotlib.pyplot as plt
import numpy as np
# 创建并绘制第一张图
x1 = np.linspace(0, 10, 100)
y1 = np.sin(x1)
fig1 = plt.figure() # 创建新的图形
plt.plot(x1, y1)
plt.title('Plot 1')
# 获取并设置窗口位置
manager1 = plt.get_current_fig_manager()
manager1.window.move(100, 100) # 设置窗口位置为 (100, 100)
# 创建并绘制第二张图
x2 = np.linspace(0, 5, 50)
y2 = np.cos(x2)
fig2 = plt.figure() # 创建新的图形
plt.plot(x2, y2)
plt.title('Plot 2')
# 获取并设置窗口位置
manager2 = plt.get_current_fig_manager()
manager2.window.move(800, 100) # 设置窗口位置为 (800, 100)
# 创建并绘制第三张图
x3 = np.linspace(-5, 5, 50)
y3 = np.tan(x3)
fig3 = plt.figure() # 创建新的图形
plt.plot(x3, y3)
plt.title('Plot 3')
# 获取并设置窗口位置
manager3 = plt.get_current_fig_manager()
manager3.window.move(400, 500) # 设置窗口位置为 (400, 500)
# 显示所有图形
plt.show()