Отображение сюжета в jupyterlab не работает. Ошибка при загрузке виджета - PullRequest
0 голосов
/ 03 августа 2020

Я пытаюсь показать график на jupyterlab на удаленном сервере, но график не отображается.

JupyterLab v2.1.5
Known labextensions:
app dir: /opt/conda/share/jupyter/lab
    @jupyter-widgets/jupyterlab-manager v2.0.0  enabled  OK
    @jupyterlab/toc v4.0.0  enabled  OK
    @krassowski/jupyterlab-lsp v1.1.0  enabled  OK
    @lckr/jupyterlab_variableinspector v0.5.1  enabled  OK
    jupyter-matplotlib v0.7.3  enabled  OK
    jupyterlab-dash v0.3.0  enabled  OK
    jupyterlab-python-file v0.4.0  enabled  OK

Это моя версия ipympl

print(ipympl.__version__)
0.5.7

и это моя версия matplotlib

print(matplotlib.__version__)
3.3.0

Это мой код

import matplotlib.pyplot as plt

%matplotlib widget

x_strat = np.arange(len(samples_per_label_training_strat))
width = 0.5
fig, ax = plt.subplots()
plt.rcParams['figure.dpi'] = 500
plt.rcParams.update({'font.size': 2.2})

rects1 = ax.bar(x_strat - width/2, samples_per_label_training_strat, width, label='Training samples')
rects2 = ax.bar(x_strat + width/2, samples_per_label_testing_strat, width, label='Testing samples')

# Add some text for labels, title and custom x-axis tick labels, etc.
ax.set_ylabel('Number of samples')
ax.set_title('Number of samples for training and testing per class')
ax.set_xticks(x_strat)
ax.set_xticklabels(lab_strat_new)
ax.legend()

plt.gca().margins(x=0)
plt.gcf().canvas.draw()
tl = plt.gca().get_xticklabels()
maxsize = max([t.get_window_extent().width for t in tl])
m = 0.5 # inch margin
s = maxsize/plt.gcf().dpi*len(x_strat)+2*m
margin = m/plt.gcf().get_size_inches()[0]

plt.gcf().subplots_adjust(left=margin, right=1.-margin)
plt.gcf().set_size_inches(s, plt.gcf().get_size_inches()[1])

autolabel(rects1)
autolabel(rects2)
plt.setp(ax.get_xticklabels(), rotation=60, horizontalalignment='right')
plt.savefig("strat_classes_plot.png")

plt.show()

и это ошибка трассировки, которую я получаю

Loading widget...

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-9-0eeab29a5615> in <module>
     31 autolabel(rects2)
     32 plt.setp(ax.get_xticklabels(), rotation=60, horizontalalignment='right')
---> 33 plt.savefig("strat_classes_plot.png")
     34 
     35 

~/semantic_env/lib/python3.8/site-packages/matplotlib/pyplot.py in savefig(*args, **kwargs)
    840 def savefig(*args, **kwargs):
    841     fig = gcf()
--> 842     res = fig.savefig(*args, **kwargs)
    843     fig.canvas.draw_idle()   # need this if 'transparent=True' to reset colors
    844     return res

~/semantic_env/lib/python3.8/site-packages/matplotlib/figure.py in savefig(self, fname, transparent, **kwargs)
   2309                 patch.set_edgecolor('none')
   2310 
-> 2311         self.canvas.print_figure(fname, **kwargs)
   2312 
   2313         if transparent:

~/semantic_env/lib/python3.8/site-packages/matplotlib/backend_bases.py in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, bbox_inches, pad_inches, bbox_extra_artists, backend, **kwargs)
   2223                 self.figure.set_edgecolor(origedgecolor)
   2224                 self.figure.set_canvas(self)
-> 2225             return result
   2226 
   2227     @classmethod

~/semantic_env/lib/python3.8/contextlib.py in __exit__(self, type, value, traceback)
    118         if type is None:
    119             try:
--> 120                 next(self.gen)
    121             except StopIteration:
    122                 return False

~/semantic_env/lib/python3.8/site-packages/matplotlib/cbook/__init__.py in _setattr_cm(obj, **kwargs)
   2064         for attr, orig in origs.items():
   2065             if orig is sentinel:
-> 2066                 delattr(obj, attr)
   2067             else:
   2068                 setattr(obj, attr, orig)

AttributeError: __delete__
...