【问题标题】:How do I get python-chess SVG rendering working in Google Colab?如何让 python-chess SVG 渲染在 Google Colab 中工作?
【发布时间】:2021-12-06 20:27:00
【问题描述】:

我正在尝试从 python-chess SVG rendering 获取此代码示例。

import chess
import chess.svg
chess.svg.piece(chess.Piece.from_symbol("R"))

当我运行代码时,我得到以下 HTML 输出,但不是白车的图像。

<svg version="1.1" viewBox="0 0 45 45" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><g class="white rook" fill="#fff" fill-rule="evenodd" id="white-rook" stroke="#000" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5"><path d="M9 39h27v-3H9v3zM12 36v-4h21v4H12zM11 14V9h4v2h5V9h5v2h5V9h4v5" stroke-linecap="butt" /><path d="M34 14l-3 3H14l-3-3" /><path d="M31 17v12.5H14V17" stroke-linecap="butt" stroke-linejoin="miter" /><path d="M31 29.5l1.5 2.5h-20l1.5-2.5" /><path d="M11 14h23" fill="none" stroke-linejoin="miter" /></g></svg>

【问题讨论】:

  • 呃,这张图片与您期望的白车外观有何不同?我的意思是,如果您让我向某人描述该图像,我会说这是白车的 2D 表示。
  • 我没有图片,我得到了以'
    这是一个 SVG 图像。 SVG 图像具有基于文本的格式。

标签: python html svg google-colaboratory python-chess


【解决方案1】:

这解决了我的问题:

import chess
import chess.svg
import IPython
html_code = chess.svg.piece(chess.Piece.from_symbol("R"))
display(IPython.display.HTML(html_code))

现在 Colab 中显示了白车。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-08-13
    • 1970-01-01
    • 2019-08-18
    • 2021-03-11
    • 2020-11-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多