簡體   English   中英

在 Jupyter Notebook 中使用 pyplot.scatter() 會導致 Jupyter Notebook 菜單中的錯誤

[英]Use pyplot.scatter() in Jupyter Notebook makes bug in the Jupyter notebook menu

jupyter notebook 菜單錯誤的圖片:

jupyter notebook 菜單錯誤的圖像。

我的代碼如下:

[%matplotlib inline
import torch
from IPython import display
from matplotlib import pyplot as plt
import numpy as np
import random

num_inputs = 2
num_examples = 1000
true_w = [2, -3.4]
true_b = 4.2
features = torch.from_numpy(np.random.normal(0, 1, (num_examples, num_inputs)))

labels = true_w[0] * features[:, 0] + true_w[1] * features[:, 1] + true_b
labels += torch.from_numpy(np.random.normal(0, 0.01, size=labels.size()))

def use_svg_display():
    display.set_matplotlib_formats('svg')

def set_figsize(figsize=(3.5, 2.5)):
    use_svg_display()
    plt.rcParams['figure.figsize'] = figsize

set_figsize()
plt.scatter(features[:, 1].numpy(), labels.numpy(), 1);

我的環境是:Windows 10,Anaconda,Python3.6。 在執行最后一行時,出現了這個問題。 我瀏覽了互聯網,但不知道是什么問題。

看到您更正的代碼后,您的 matplotlib 版本中的 svg 渲染看起來像是一個錯誤。 有關相同問題,請參閱此 github問題。 看起來您需要按照帖子中的建議將 matplotlib 版本更新為 3.1.1 或恢復為 3.0.3,方法是在終端中執行conda install matplotlib=3.0.3並重新啟動筆記本。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM