在jupyterlab中显示情节不起作用。加载小部件时出错

时间:2020-08-03 16:50:16

标签: python-3.x matplotlib jupyter-lab

我正在尝试在远程服务器上的jupyterlab上显示图,但是该图不会显示。

WHERE ("entity_id" = 'speedtest_ping' AND "value" < 200)

这是我的ipympl版本

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

这是我的matplotlib版本

print(ipympl.__version__)
0.5.7

这是我的代码

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()

0 个答案:

没有答案