我在Macbook Pro(OSX 10.13.6)上使用带有Matplotlib的plt.show()绘制数据时,似乎总是发生此问题。如果创建一个Pandas数据框并使用Matplotlib绘制数据,然后在交互式窗口(使用plt.show)中在屏幕上显示结果,则该窗口(和matplotlib)通常会崩溃。如果在屏幕上完成了用于向上或向下滚动的鼠标手势,则总是会发生这种情况。其他时候,它似乎是随机发生的。
剧情崩溃时,我将此作为回溯:
Traceback (most recent call last):
File "./plot_lc_vs_gnss.py", line 117, in <module>
main()
File "./plot_lc_vs_gnss.py", line 28, in main
plt.show()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/pyplot.py", line 253, in show
return _show(*args, **kw)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/backend_bases.py", line 208, in show
cls.mainloop()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/matplotlib/backends/_backend_tk.py", line 1073, in mainloop
Tk.mainloop()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/tkinter/__init__.py", line 557, in mainloop
_default_root.tk.mainloop(n)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte
我正在读取的数据是一个简单的CSV,以前也是由熊猫生成的。我正在用一个简单的脚本生成绘图,如下所示:
#!/usr/local/bin/python3
import matplotlib
matplotlib.use('TkAgg')
import json
import os
import numpy as np
import pandas as pd
import pymap3d as pm
import matplotlib.pyplot as plt
def load_csvs():
gnss = pd.read_csv('di3_d4_1017_gnss.csv')
ins = pd.read_csv('di3_d4_1017_ins.csv')
return gnss, ins
def plot_cdf(gnss, ins):
data = [gnss, ins]
plt.figure(figsize=[12,9])
ax = plt.subplot(1,1,1)
for ds in data:
if ds[err].any != np.nan:
dsorted = np.sort(ds['horizontal_error'])
yvals = np.arange(len(dsorted)) / float(len(dsorted) - 1) * 100
ax.plot(dsorted, yvals)
ax.grid()
ax.set_xlabel('Horizontal Error (m)')
ax.set_ylabel('Percent of Epochs')
title = 'Drive Test data \n DI-3 (roof) d4_1017 \n CDF Horizontal Error'
plt.title(title)
plt.legend(['gnss', 'ins'], loc='lower right')
def main():
gnss, ins = load_csvs()
plot_cdf(gnss, ins)
plt.show()
if __name__ == "__main__":
main()
任何有关如何解决此问题的建议将不胜感激。