简体   繁体   中英

Matplotlib interactive plots crash if mouse scroll used on plot

This issue seems to happen any time I plot data using plt.show() with Matplotlib on my Macbook Pro (OSX 10.13.6). If I create a Pandas dataframe and plot the data with Matplotlib, then show the result on the screen in the interactive window (using plt.show), the window (and matplotlib) will often crash. It will always happen if the mouse gesture for scroll-up or down is done on the screen. Other times it seems to happen at random.

When the plot crashes i get this as a traceback:

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

The data I am reading in is a simple CSV that was previously generated by pandas as well. I am generating the plot with a simple script like this:

#!/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() 

Any advice on how to fix this issue would be greatly appreciated.

我想到现在没关系,但这似乎是一个未解决的问题,正在#9637中进行讨论

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM