V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
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
Alias4ck
V2EX  ›  Python

如何使用 Matplotlib 实现这张图

  •  1
     
  •   Alias4ck · 2022-10-10 14:15:44 +08:00 · 1892 次点击
    这是一个创建于 535 天前的主题,其中的信息可能已经有所发展或是发生改变。

    最近做Project Euler 94题的时候

    看到一个解法 Pell's equation 看到维基百科里面有一张图 https://en.wikipedia.org/wiki/File:Pell%27s_equation.svg

    描述这个基本方程的解法,出于好奇,想用Numpy或者Sympy 加上Matplotlib 画出这个图

    由于不是很熟悉这些工具包的使用,看看有没有大佬有解决方案

    3 条回复    2022-10-10 19:45:11 +08:00
    takato
        1
    takato  
       2022-10-10 15:00:57 +08:00   ❤️ 1
    ```python
    from sympy import symbols
    from sympy.plotting import plot_implicit

    x, y = symbols('x y')
    p1 = plot_implicit(x*x - 2*y*y - 1)
    p1
    ```

    可参考: https://stackoverflow.com/questions/73837545/sympy-plot-x-y-equation-as-a-curve-without-solve-it
    Alias4ck
        2
    Alias4ck  
    OP
       2022-10-10 15:10:44 +08:00
    @takato 大佬牛 原来 sympy 集成了 不解决问题的 plot 方法啊
    necomancer
        3
    necomancer  
       2022-10-10 19:45:11 +08:00
    隐函数一般用 contour
    ipython --pylab

    ```python
    x = np.linspace(-5,5,100)
    X, Y = np.meshgrid(x,x)
    ax = contour(X**2-2*Y**2-1, levels=[0], origin='lower', extent=[-5,5,-5,5])
    ```
    Grid 和上面的点以及 annotation 一类的你具体查查手册吧,怎么对 ax 一顿操作就有了
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1000 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 20:00 · PVG 04:00 · LAX 13:00 · JFK 16:00
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.