简体   繁体   English

在 Jupyter Notebook 中使用 pyplot.scatter() 会导致 Jupyter Notebook 菜单中的错误

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

The image of the jupyter notebook menu error: jupyter notebook 菜单错误的图片:

jupyter notebook 菜单错误的图像。

My code as follow:我的代码如下:

[%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);

My environment is: Windows 10, Anaconda, Python3.6.我的环境是:Windows 10,Anaconda,Python3.6。 When executing the last line, this problem occured.在执行最后一行时,出现了这个问题。 I have looked through the Internet but have no idea what't the problem.我浏览了互联网,但不知道是什么问题。

After seeing your corrected code, it looks like this is an error with the svg rendering in your matplotlib version.看到您更正的代码后,您的 matplotlib 版本中的 svg 渲染看起来像是一个错误。 See this github issue about the same problem.有关相同问题,请参阅此 github问题。 It looks like you'll want to update your matplotlib version to 3.1.1 or revert to 3.0.3 as suggested in the post, by doing conda install matplotlib=3.0.3 in the terminal and restarting your notebook.看起来您需要按照帖子中的建议将 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