因此,它似乎在Ubuntu的Windows(Windows子系统为Linux)人们建议我们需要使用Agg后端,只保存图像,而不是显示情节。在Ubuntu中显示matplotlib图(Linux子系统的Windows子系统)
import matplotlib
matplotlib.use('Agg') # no UI backend
import matplotlib.pyplot as plt
import numpy as np
t = np.arange(0.0, 2.0, 0.01)
s = 1 + np.sin(2*np.pi*t)
plt.plot(t, s)
plt.title('About as simple as it gets, folks')
#plt.show()
plt.savefig("matplotlib.png") #savefig, don't show
我们怎样才能把它放到plt.show()实际显示图像的位置?我目前的选择是重写plot.show(),而不是只保存在/ mnt/c/Users/james/plots /下的plot-148123456.png窗口中,只需打开浏览器窗口即可查看图像。
我想我可以托管该文件夹并使用浏览器。
我的目标是能够像上面的代码一样运行简单的示例,而不需要将代码更改为ftp图像等等。我只希望剧情出现在窗口中。
有没有人想出了一个体面的方式来做到这一点?
在[这个问题](http://stackoverflow.com/questions/40566837/no-plot-window-in-matplotlib-in-linux-shell-windows-10)答案表示,这将是可能的为此目的使用xming。你也可以考虑在SuperUser中提出一个类似的问题(不要过多地关注matplotlib)。 – ImportanceOfBeingErnest