在调用matplotlib.pyplot库画图时,如何设置其在固定位置显示。how-do-you-set-the-absolute-position-of-figure-windows-with-matplotlib
其实问题在于你要搞清楚你的plt后端编译器的类型。有TkAgg,WXAgg,Qt5Agg等类型。怎么查看自己的后端编译器,可以这样
import matplotlib
import matplotlib.pyplot as plt
backend = matplotlib.get_backend()
print(backend)
当类型为TkAgg时,可以这样写:
import matplotlib
import matplotlib.pyplot as plt
from PIL import Image
img = Image.open("00.jpg")
fig = plt.figure()
fig.canvas.manager.window.wm_geometry('+300+300')
fig.imshow(img)
fig.show()
这是显示一张图片,但一般用固定窗口位置都是序列图像的显示
当类型为WXAgg时,可以这样写:
import matplotlib
import matplotlib.pyplot as plt
from PIL import Image
img = Image.open("00.jpg")
fig = plt.figure()
fig.canvas.manager.window.SetPosition((300, 300))
fig.imshow(img)
fig.show()
当类型为Qt5Agg时,可以这样写:
import matplotlib
import matplotlib.pyplot as plt
from PIL import Image
img = Image.open("00.jpg")
fig = plt.figure()
f.canvas.manager.window.move(300, 300)
fig.imshow(img)
fig.show()
搞定~,因为看到一篇讲这个相关的博文,但是没有解决我的问题,就去论坛上看到了具体的解决办法。
还有就是如何显示不带白边的plt图像
plt.figure()
fig.set_size_inches(2,2)#200x200
fig.canvas.manager.window.move(300,300)
plt.imshow('your img sequence array')
plt.axis('off')
plt.gca().xaxis.set_major_locator(plt.NullLocator())
plt.gca().yaxis.set_major_locator(plt.NullLocator())
plt.subplots_adjust(top=1,bottom=0,left=0,right=1,hspace=0,wspace=0)
plt.margins(0,0)
plt.pause(0.5)
这样就可以连续固定位置显示图像了。