推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
jememouse
V2EX  ›  Python

如何用 Python 画一条 10cm 的线条和直径 10cm 的圆,并输出成矢量的 pdf 和 svg?

  •  
  •   jememouse · Jun 21, 2020 · 4767 views
    This topic created in 2176 days ago, the information mentioned may be changed or developed.

    如何用 python 画一条 10cm 的线条和直径 10cm 的圆,并输出成矢量的 pdf 和 svg ? 试过用 matplotlib,无法实现。 刚学习 python,请大家指教。

    13 replies    2020-06-21 23:38:53 +08:00
    Tony042
        1
    Tony042  
       Jun 21, 2020
    matplotlib 可以保存成 pdf 或 svg 啊, https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.pyplot.savefig.html 仔细看 format parameter 的描述
    vk42
        2
    vk42  
       Jun 21, 2020
    matplotlib 当然能实现,但你得先看看文档上手,不过你这需求拿文档样例改改都行了……

    另外如果是想要直观的数学作图可以试试 geogebra,上手容易很多而且是交互式作图
    jdhao
        3
    jdhao  
       Jun 21, 2020 via Android   ❤️ 1
    不知道你是怎么试的,问问题只是都没上网搜一下,matplotlib 保存 pdf,网上一大堆教程。别这么懒
    dingyaguang117
        4
    dingyaguang117  
       Jun 21, 2020
    直接用 sketch 画一个,看看源码, 然后用自己拼不行吗
    ethego
        5
    ethego  
       Jun 21, 2020
    哪有十厘米的线,电子世界只有像素,一个像素多宽多长是不确定的。
    610915518
        6
    610915518  
       Jun 21, 2020
    5 楼说的对。建议使用 Photoshop 等软件,新建个 A4 纸,然后按比例画线和圆,这样才能画出 10 厘米的 X 。
    zhuweiyou
        7
    zhuweiyou  
       Jun 21, 2020
    厘米?建议别学编程了。
    vk42
        8
    vk42  
       Jun 21, 2020
    @ethego 画布大小设定好的情况当然是可以对应到具体尺寸的
    Shy07
        9
    Shy07  
       Jun 21, 2020
    矢量作图可以用 pt 做单位,文字、图形都可以用,10 cm 对应的 pt 可以用公式计算出来

    const mm2pt = value => parseFloat(value) * 360 / 127
    Zhepro
        10
    Zhepro  
       Jun 21, 2020
    PIL 的 imagedraw 比较方便,可以画 png 的图
    cuminflea
        11
    cuminflea  
       Jun 21, 2020 via iPad   ❤️ 1
    svgwrite 的库,专门画 svg 的
    izoabr
        12
    izoabr  
       Jun 21, 2020
    10L 说的对
    jememouse
        13
    jememouse  
    OP
       Jun 21, 2020
    @cuminflea 非常感谢,学习了!
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3156 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 67ms · UTC 02:49 · PVG 10:49 · LAX 19:49 · JFK 22:49
    ♥ Do have faith in what you're doing.