前提
https://jimaru.blog/programming/python/matplotlib-data-map-visualization/#st-toc-h-1
↑リンクを参考に、google colaboratoryで画像を表示させようとするとNotImplementedErrorが出てしまいましたが改善点がわかりません。
発生している問題・エラーメッセージ
--------------------------------------------------------------------------- NotImplementedError Traceback (most recent call last) <ipython-input-30-6d74c1ea80e3> in <module> 6 7 map_image = Image.open('kamitonda.jpg') ----> 8 plt.imshow(map_image) 9 map_image.close() 12 frames /usr/local/lib/python3.7/dist-packages/matplotlib/pyplot.py in imshow(X, cmap, norm, aspect, interpolation, alpha, vmin, vmax, origin, extent, shape, filternorm, filterrad, imlim, resample, url, data, **kwargs) 2643 # Autogenerated by boilerplate.py. Do not edit as changes will be lost. 2644 @_copy_docstring_and_deprecators(Axes.imshow) -> 2645 def imshow( 2646 X, cmap=None, norm=None, aspect=None, interpolation=None, 2647 alpha=None, vmin=None, vmax=None, origin=None, extent=None, *, /usr/local/lib/python3.7/dist-packages/matplotlib/pyplot.py in gca(**kwargs) 877 878 def get_figlabels(): --> 879 """Return a list of existing figure labels.""" 880 managers = _pylab_helpers.Gcf.get_all_fig_managers() 881 managers.sort(key=lambda m: m.num) /usr/local/lib/python3.7/dist-packages/matplotlib/pyplot.py in gcf() 609 Turn on `xkcd <https://xkcd.com/>`_ sketch-style drawing mode. This will 610 only have effect on things drawn after this function is called. --> 611 612 For best results, the "Humor Sans" font should be installed: it is 613 not included with Matplotlib. /usr/local/lib/python3.7/dist-packages/matplotlib/pyplot.py in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, clear, **kwargs) 544 def pause(interval): 545 """ --> 546 Run the GUI event loop for *interval* seconds. 547 548 If there is an active figure, it will be updated and displayed before the /usr/local/lib/python3.7/dist-packages/matplotlib/backend_bases.py in new_figure_manager(cls, num, *args, **kwargs) 3356 image = self._get_image_filename(tool.image) 3357 toggle = getattr(tool, 'toggled', None) is not None -> 3358 self.add_toolitem(tool.name, group, position, 3359 image, tool.description, toggle) 3360 if toggle: /usr/local/lib/python3.7/dist-packages/ipympl/backend_nbagg.py in new_figure_manager_given_figure(num, figure) 485 if 'nbagg.transparent' in rcParams and rcParams['nbagg.transparent']: 486 figure.patch.set_alpha(0) --> 487 manager = FigureManager(canvas, num) 488 489 if is_interactive(): /usr/local/lib/python3.7/dist-packages/ipympl/backend_nbagg.py in __init__(self, canvas, num) 457 458 def __init__(self, canvas, num): --> 459 FigureManagerWebAgg.__init__(self, canvas, num) 460 self.web_sockets = [self.canvas] 461 self.toolbar = Toolbar(self.canvas) /usr/local/lib/python3.7/dist-packages/matplotlib/backends/backend_webagg_core.py in __init__(self, canvas, num) 458 self.web_sockets = set() 459 super().__init__(canvas, num) --> 460 self.toolbar = self._get_toolbar(canvas) 461 462 def show(self): /usr/local/lib/python3.7/dist-packages/matplotlib/backends/backend_webagg_core.py in _get_toolbar(self, canvas) 464 465 def _get_toolbar(self, canvas): --> 466 toolbar = self.ToolbarCls(canvas) 467 return toolbar 468 /usr/local/lib/python3.7/dist-packages/ipympl/backend_nbagg.py in __init__(self, canvas, *args, **kwargs) 120 def __init__(self, canvas, *args, **kwargs): 121 DOMWidget.__init__(self, *args, **kwargs) --> 122 NavigationToolbar2WebAgg.__init__(self, canvas, *args, **kwargs) 123 124 self.on_msg(self.canvas._handle_message) /usr/local/lib/python3.7/dist-packages/matplotlib/backends/backend_webagg_core.py in __init__(self, canvas) 420 self.message = '' 421 self._cursor = None # Remove with deprecation. --> 422 super().__init__(canvas) 423 424 def set_message(self, message): /usr/local/lib/python3.7/dist-packages/matplotlib/backend_bases.py in __init__(self, canvas) 2706 if button_name in rcParams['keymap.back']: 2707 toolbar.back() -> 2708 elif button_name in rcParams['keymap.forward']: 2709 toolbar.forward() 2710 /usr/local/lib/python3.7/dist-packages/matplotlib/backend_bases.py in _init_toolbar(self) 2769 The default mouse button handler cid, when using the toolmanager. 2770 To disable the default button press handling use:: -> 2771 2772 figure.canvas.mpl_disconnect( 2773 figure.canvas.manager.button_press_handler_id) NotImplementedError:
該当のソースコード
エラーが出ているのはplt.imshow(map_image)のところです。
!pip install ipympl
python
1import matplotlib 2import matplotlib.pyplot as plt 3from PIL import Image 4 5%matplotlib ipympl 6 7map_image = Image.open('map.jpg') 8plt.imshow(map_image) 9map_image.close()
>解説もjupyterlab環境を前提にしていきます。
は読んでいないのでしょうか。
他のサイト(例)https://qiita.com/croquette0212/items/36cadce5bf0fb703ed19)でcolaboratoryを利用しているものがあったので、そちらのコードを使用してみたところ同じようにplt.imshow()でエラーが出たため開発環境の違いは考えていませんでした。
そも
%matplotlib inline
ではないでしょうか?もしくは
%matplotlib widget
https://stackoverflow.com/questions/58845278/matplotlib-and-google-colab-using-ipympl
おっしゃる通り%matplotlib inline にするとNotImplementedErrorは解消され、ImportErrorがでました。%matplotlib ipymplの部分を深く考えていませんでしたすみません。
※ちなみに%matplotlib widgetではNotImplementedErrorのままでした。
解決できてよかったです.
解決に至るためのコード変更点を下の解答欄に書いて自己解決にしてください.
ImportErrorに関しては,別問題ですので新たな質問を立てることが推奨されています.
ありがとうございました。importErrorも無事解決できたので自己解決として掲載させていただきました。
回答1件
あなたの回答
tips
プレビュー