ValueError: 'svg' is not a valid value for output; supported values are 'path', 'agg', 'macosx'

colab运行李沐的动手学深度学习
画图就报错这个了
ValueError: 'svg' is not a valid value for output; supported values are 'path', 'agg', 'macosx'

感觉有可能是d2l版本的问题。我尝试了一下安装其他旧版本的d2l,代码是

img


然后图片就可以正常输出了,亲测有效

img

同样的问题,蹲。我感觉应该是Matplotlib版本问题

同样遇到了这个问题


# 李沐的代码里面有这个
# 提高显示图片的清晰度
  d2l.use_svg_display()

# 点开源码看见
  def use_svg_display():
    """Use the svg format to display a plot in Jupyter.

    Defined in :numref:`sec_calculus`"""
    backend_inline.set_matplotlib_formats('svg')   #  将这个svg 改为里面其他的formats           'png', 'retina', 'jpeg', 'svg', 'pdf'.            就行了

# 我这里直接在我代码里面添加
from matplotlib_inline import backend_inline

backend_inline.set_matplotlib_formats('png')

有人解决吗

81格svg改为png

这个错误提示是因为Matplotlib不支持将图形以SVG格式输出,而SVG格式是默认的输出格式之一。为了解决这个问题,你可以通过设置输出格式来避免使用SVG。代码示例如下:

import matplotlib.pyplot as plt

# 设置输出格式为png
plt.rcParams['svg.fonttype'] = 'none'
plt.rcParams['savefig.format'] = 'png'

当然,你也可以将输出格式设置为其他格式,如JPG、PDF等,只需要将对应的文件格式替换上面的'png'即可。