質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

Q&A

解決済

1回答

2558閲覧

terminating with uncaught exception of type NSException のエラー

退会済みユーザー

退会済みユーザー

総合スコア0

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

0グッド

0クリップ

投稿2017/11/07 13:03

terminating with uncaught exception of type NSException とエラーが出ました。

@login_required def past_result(request): return render(request, 'registration/past_result.html',{'chart':_view_plot(request)}) def _view_plot(request): results = ImageAndUser.objects.filter(user=request.user).order_by('-consultation_date') dates = [r.consultation_date for r in reversed(results)] heights = [r.x_ray for r in reversed(results)] scores = [1, 2, 3, 4, 5] df = pd.DataFrame() df['受検日'] = ['2016-04-01', '2016-04-02', '2016-04-03'] df['calories'] = [2200, 2100, 1500] df['sleep hours'] = [2200, 2100, 1500] col_width = 3.0 row_height = 0.625 font_size = 14 header_color = '#40466e' row_colors = ['#f1f1f2', 'w'] edge_color = 'w' bbox = [0, 0, 1, 1] header_columns = 0 ax = None if ax is None: size = (np.array(df.shape[::-1]) + np.array([0, 1])) * np.array([col_width, row_height]) fig, ax = plt.subplots(figsize=size) ax.axis('off') mpl_table = ax.table(cellText=df.values, bbox=bbox, colLabels=df.columns) mpl_table.auto_set_font_size(False) mpl_table.set_fontsize(font_size) for k, cell in six.iteritems(mpl_table._cells): cell.set_edgecolor(edge_color) if k[0] == 0 or k[1] < header_columns: cell.set_text_props(weight='bold', color='w') cell.set_facecolor(header_color) else: cell.set_facecolor(row_colors[k[0] % len(row_colors)]) return ax,plt.show()

とコードを書きました。
past_resultメソッドを呼び出すと、Pythonが予期せぬエラーで停止しました、とエラーが出て、

Traceback (most recent call last): File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/artist.py", line 55, in draw_wrapper draw(artist, renderer, *args, **kwargs) File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/figure.py", line 1034, in draw func(*args) File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/artist.py", line 55, in draw_wrapper draw(artist, renderer, *args, **kwargs) File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/axes.py", line 2086, in draw a.draw(renderer) File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/artist.py", line 55, in draw_wrapper draw(artist, renderer, *args, **kwargs) File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/table.py", line 243, in draw self._cells[key].draw(renderer) File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/artist.py", line 55, in draw_wrapper draw(artist, renderer, *args, **kwargs) File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/table.py", line 101, in draw self._text.draw(renderer) File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/artist.py", line 55, in draw_wrapper draw(artist, renderer, *args, **kwargs) File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/text.py", line 547, in draw bbox, info, descent = self._get_layout(renderer) File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/text.py", line 325, in _get_layout clean_line, ismath = self.is_math_text(line) File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/text.py", line 1000, in is_math_text if cbook.is_math_text(s): File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/cbook.py", line 1927, in is_math_text "matplotlib display text must have all code points < 128 or use " ValueError: matplotlib display text must have all code points < 128 or use Unicode strings 2017-11-07 12:58:34.262 Python[82658:1927912] WARNING: nextEventMatchingMask should only be called from the Main Thread! This will throw an exception in the future. 2017-11-07 12:58:34.262 Python[82658:1927912] *** Assertion failure in +[NSUndoManager _endTopLevelGroupings], /Library/Caches/com.apple.xbs/Sources/Foundation/Foundation-1349.64/Misc.subproj/NSUndoManager.m:363 2017-11-07 12:58:34.269 Python[82658:1927912] *** Assertion failure in +[NSUndoManager _endTopLevelGroupings], /Library/Caches/com.apple.xbs/Sources/Foundation/Foundation-1349.64/Misc.subproj/NSUndoManager.m:363 2017-11-07 12:58:34.273 Python[82658:1927912] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '+[NSUndoManager(NSInternal) _endTopLevelGroupings] is only safe to invoke on the main thread.' *** First throw call stack: ( 0 CoreFoundation 0x00007fffc96b737b __exceptionPreprocess + 171 1 libobjc.A.dylib 0x00007fffde4b348d objc_exception_throw + 48 2 CoreFoundation 0x00007fffc96bc082 +[NSException raise:format:arguments:] + 98 3 Foundation 0x00007fffcb103ce0 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 195 4 Foundation 0x00007fffcb08e3b3 +[NSUndoManager(NSPrivate) _endTopLevelGroupings] + 170 5 AppKit 0x00007fffc711e8bd -[NSApplication run] + 1200 6 _macosx.so 0x00000001051268d2 init_macosx + 32564 7 Python 0x00000001000c4fd5 PyEval_EvalFrameEx +                        ・                    (長いので省略)                        ・ 146 Python 0x0000000100106897 t_bootstrap + 71 147 libsystem_pthread.dylib 0x00007fffdefb19af _pthread_body + 180 148 libsystem_pthread.dylib 0x00007fffdefb18fb _pthread_body + 0 149 libsystem_pthread.dylib 0x00007fffdefb1101 thread_start + 13 ) libc++abi.dylib: terminating with uncaught exception of type NSException [1] 82657 abort python manage.py runserver

とTracebackに出ました。なぜ普通の文法エラーではなく、このようなエラーが出てしまうのでしょうか?どう直せば良いのでしょうか?

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

ValueError: matplotlib display text must have all code points < 128 or use Unicode stringsとありますので、まずはmatplotlibに入る文字列をUTF8にするかユニコードで指定してください。

後半のエラーは、matplotlibが食えないデータ(UTF-8でもユニコードでもないデータ)を無理やり食わされてOSがコケたとかそういう話ではないでしょうか。

投稿2017/11/07 22:06

退会済みユーザー

退会済みユーザー

総合スコア0

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問