V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
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 · Oct 10, 2022 · 2590 views
    This topic created in 1299 days ago, the information mentioned may be changed or developed.

    最近做Project Euler 94题的时候

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

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

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

    3 replies    2022-10-10 19:45:11 +08:00
    takato
        1
    takato  
       Oct 10, 2022   ❤️ 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
       Oct 10, 2022
    @takato 大佬牛 原来 sympy 集成了 不解决问题的 plot 方法啊
    necomancer
        3
    necomancer  
       Oct 10, 2022
    隐函数一般用 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 一顿操作就有了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1874 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 00:01 · PVG 08:01 · LAX 17:01 · JFK 20:01
    ♥ Do have faith in what you're doing.