Skip to main content

yaplotlib

Yaplot 形式の描画データを Python から作るライブラリです。

描画コマンドは種類(line や circle など)と座標の列で表します。種類ごとの違いはライブラリ内部の表にまとめてあり、呼び出し側は同じ add を使います。複数フレームと、ファイル先頭の global ブロック、画面に固定する SVG は YaplotDocument が持ちます。

インストール

pip install yaplotlib

numpy が必要です。

クイックスタート

import numpy as np
from yaplotlib import YaplotDocument

doc = YaplotDocument()
doc.globals.fov = 30
doc.globals.radius = 0.3

xyz = np.array([[0.0, 0.0, 0.0], [1.0, 0.0, 0.0], [0.0, 1.0, 0.0]])
path = np.array([[0.0, 0.0, 0.0], [0.5, 0.2, 0.0], [1.0, 0.0, 0.0]])

for t in range(len(path)):
    frame = doc.new_frame()
    frame.add_many("circle", xyz, color=3)
    frame.add("stick", (0, 0, 0), (1, 0, 0), arrow=1, color=4)
    if t >= 1:
        # polyline は、Yaplot が受け付けるようになるまで線分に分解して出力する
        frame.add("polyline", *path[: t + 1], color=5)
    frame.add("text", (0, 0, 0), text=f"t = {t}")

doc.save("movie.yap")

color、layer、radius、arrow を省略すると、その項目は出力されません。直前の値を引き継ぐので、色を指定した要素の後ろに置いた色なしの要素は、その色で描かれます。

global ブロック

doc.globals に置いた値は、すべてのフレームの初期状態になります。何も設定しなければ global ブロックは出力しません。

  • 見た目: layer, color, radius, arrow, palettes
  • 表示の初期状態: reality(0..4), splat(0..3), fov, verbose(0..3), thickness, rotation(1〜3 個の数値), fps, hide, show, messages
  • 全フレーム共通の SVG: add_svg
doc.globals.reality = 3
doc.globals.palettes[3] = (255, 100, 100)
doc.globals.messages.append("loaded")

SVG

画面に固定する 2D の情報(見出し、凡例、グラフ)は SVG のまま渡します。global に置くと全フレーム、フレームに置くとそのフレームだけに出ます。matplotlib の Figure も渡せます(背景は透明になります)。

frame.add_svg('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512">'
              '<text x="16" y="32" fill="white">t = 0</text></svg>')
frame.add_svg(figure)          # matplotlib の Figure
doc.globals.add_svg("hud.svg")  # ファイル

まとめて追加する

add_many は座標を ndarray のまま保持します。形は「個数 N × 1 個あたりの座標数 × 3」です。

種類 形
circle, ring, triangle, square, pentagon, hexagon, text (N, 3)
line, stick (N, 2, 3)
polygon, polyline(頂点数がそろうとき) (N, m, 3)

line の始点と終点が別の配列なら np.stack([starts, ends], axis=1) で重ねます。text には長さ N の texts も渡します。

starts = np.zeros((10, 3))
ends = np.ones((10, 3))
frame.add_many("line", np.stack([starts, ends], axis=1), color=3)

パレット

from yaplotlib.palettes import rainbow_colors

doc.globals.palettes.update(enumerate(rainbow_colors(8), start=10))
frame.palette(3, (255, 96, 96))
frame.palettes(rainbow_colors(8), offset=10)

random_colors と gradation_colors も同じように RGB のリストを返します。

以前の API

モジュールの関数(Line, Circle, Color, SetPalette など)と、Line や Color のような大文字のメソッドは、DeprecationWarning を出して残してあります。Yaplot は 1 フレームだけの YaplotFrame の別名です。

from yaplotlib import Yaplot

drawing = Yaplot()
drawing.Points([(0, 0, 0), (1, 0, 0)], color=2, size=0.3)
drawing.save("example.yaplot")

ライセンス

本リポジトリの LICENSE ファイルを参照してください。

Metadata

Release files for yaplotlib 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for yaplotlib 1.0.0
File Size Uploaded Provenance Actions
yaplotlib-1.0.0.tar.gz 18.0 kB Without provenance Details for yaplotlib-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for yaplotlib 1.0.0
File Interpreter ABI Platform Actions
yaplotlib-1.0.0-py3-none-any.whl Python 3 none any Details for yaplotlib-1.0.0-py3-none-any.whl

Total release size: 40.5 kB

Release files / yaplotlib-1.0.0.tar.gz

Download URL yaplotlib-1.0.0.tar.gz
Size 18.0 kB
Tags Source
SHA-256 checksum
How to use checksums
4ed869d2fb3186e562a3c45a6980dcfc3e0c7ed900636e4c170def5fcbb96f2d
BLAKE2b-256 checksum
How to use checksums
81f112c54de2eb197e8b6c6a7f970148666b52d203cfcd26e8f40db3c33d2463
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.3.2 CPython/3.10.19 Darwin/25.5.0

Release files / yaplotlib-1.0.0-py3-none-any.whl

Download URL yaplotlib-1.0.0-py3-none-any.whl
Size 22.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
eb1cbca5ab6db6cc9a127c75ee46202d571b2210ecb1d6f388a762aea7f60b7a
BLAKE2b-256 checksum
How to use checksums
910d042e1c2bef0dc9bc3632a4de389d05fce30be627d1639f19c10c0192b37c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.3.2 CPython/3.10.19 Darwin/25.5.0

Security for yaplotlib 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page