K idZddlmZddlmZmZddlmZddlm Z m Z ddl m Z ddl mZddlmZd d giZed  ddZy )aQImplicit plotting module for SymPy. Explanation =========== The module implements a data series called ImplicitSeries which is used by ``Plot`` class to plot implicit plots for different backends. The module, by default, implements plotting using interval arithmetic. It switches to a fall back algorithm if the expression cannot be plotted using interval arithmetic. It is also possible to specify to use the fall back algorithm for all plots. Boolean combinations of expressions cannot be plotted by the fall back algorithm. See Also ======== sympy.plotting.plot References ========== .. [1] Jeffrey Allen Tupper. Reliable Two-Dimensional Graphing Methods for Mathematical Formulae with Two Free Variables. .. [2] Jeffrey Allen Tupper. Graphing Equations with Generalized Interval Arithmetic. Master's thesis. University of Toronto, 1996 )Tuple)DummySymbol) _sort_gens)ImplicitSeries_set_discretization_points) plot_factory)doctest_depends_on)flatten plot_implicit matplotlib)r )modulesNc P||fD cgc]} | |  } } |j} tt| j} | | z } t| | zdkDr t dtddfd}t| dk(rt t | } || d}|d}t| dk7rM|| vs| s(| jtd|jzn| j| j|| d }t|t}t||||||| }td |d dD|d <td |d dD|d<|jd|d|jd|dt|fi|}|r|j!|Scc} w)aMA plot function to plot implicit equations / inequalities. Arguments ========= - expr : The equation / inequality that is to be plotted. - x_var (optional) : symbol to plot on x-axis or tuple giving symbol and range as ``(symbol, xmin, xmax)`` - y_var (optional) : symbol to plot on y-axis or tuple giving symbol and range as ``(symbol, ymin, ymax)`` If neither ``x_var`` nor ``y_var`` are given then the free symbols in the expression will be assigned in the order they are sorted. The following keyword arguments can also be used: - ``adaptive`` Boolean. The default value is set to True. It has to be set to False if you want to use a mesh grid. - ``depth`` integer. The depth of recursion for adaptive mesh grid. Default value is 0. Takes value in the range (0, 4). - ``n`` integer. The number of points if adaptive mesh grid is not used. Default value is 300. This keyword argument replaces ``points``, which should be considered deprecated. - ``show`` Boolean. Default value is True. If set to False, the plot will not be shown. See ``Plot`` for further information. - ``title`` string. The title for the plot. - ``xlabel`` string. The label for the x-axis - ``ylabel`` string. The label for the y-axis Aesthetics options: - ``line_color``: float or string. Specifies the color for the plot. See ``Plot`` to see how to set color for the plots. Default value is "Blue" plot_implicit, by default, uses interval arithmetic to plot functions. If the expression cannot be plotted using interval arithmetic, it defaults to a generating a contour using a mesh grid of fixed number of points. By setting adaptive to False, you can force plot_implicit to use the mesh grid. The mesh grid method can be effective when adaptive plotting using interval arithmetic, fails to plot with small line width. Examples ======== Plot expressions: .. plot:: :context: reset :format: doctest :include-source: True >>> from sympy import plot_implicit, symbols, Eq, And >>> x, y = symbols('x y') Without any ranges for the symbols in the expression: .. plot:: :context: close-figs :format: doctest :include-source: True >>> p1 = plot_implicit(Eq(x**2 + y**2, 5)) With the range for the symbols: .. plot:: :context: close-figs :format: doctest :include-source: True >>> p2 = plot_implicit( ... Eq(x**2 + y**2, 3), (x, -3, 3), (y, -3, 3)) With depth of recursion as argument: .. plot:: :context: close-figs :format: doctest :include-source: True >>> p3 = plot_implicit( ... Eq(x**2 + y**2, 5), (x, -4, 4), (y, -4, 4), depth = 2) Using mesh grid and not using adaptive meshing: .. plot:: :context: close-figs :format: doctest :include-source: True >>> p4 = plot_implicit( ... Eq(x**2 + y**2, 5), (x, -5, 5), (y, -2, 2), ... adaptive=False) Using mesh grid without using adaptive meshing with number of points specified: .. plot:: :context: close-figs :format: doctest :include-source: True >>> p5 = plot_implicit( ... Eq(x**2 + y**2, 5), (x, -5, 5), (y, -2, 2), ... adaptive=False, n=400) Plotting regions: .. plot:: :context: close-figs :format: doctest :include-source: True >>> p6 = plot_implicit(y > x**2) Plotting Using boolean conjunctions: .. plot:: :context: close-figs :format: doctest :include-source: True >>> p7 = plot_implicit(And(y > x, y > -x)) When plotting an expression with a single variable (y - 1, for example), specify the x or the y variable explicitly: .. plot:: :context: close-figs :format: doctest :include-source: True >>> p8 = plot_implicit(y - 1, y_var=y) >>> p9 = plot_implicit(x - 1, x_var=x) Nz>Implicit plotting is not implemented for more than 2 variablesct|trt|zSt|dk(rt|St d|z)Nz2symbol or `(symbol, min, max)` expected but got %s) isinstancerrlen ValueError)s default_ranges b/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sympy/plotting/plot_implicit.py _range_tuplez#plot_implicit.._range_tuplesC a 8m+ + q6Q;!9 MPQQRRrzf(%s))adaptivedepthn line_colorc32K|]}t|ywNfloat).0xs r z plot_implicit..A58Axlimc32K|]}t|ywr#r$)r&ys rr(z plot_implicit..r)r*ylimxlabelylabel) free_symbolsrr rNotImplementedErrorlistrappendrnamepoprrtuple setdefaultr show)exprx_vary_varrrr r!r9kwargsixyvarr1 range_symbols undeclaredrvar_start_end_xr'var_start_end_yseries_argumentprs @rr r ,sd 81!-Q 8E 8$$L75>*77M -J <- '(1,!#:; ;"aLMS 5zQZ -."58,OA 5zQ ?* LLw/0 1 LL) *"58,O ' ?F$ o $O A_QR-@AAF6NA_QR-@AAF6N h 23 h 23_//A   HW 9s F#F#)NNTri,blueT)__doc__sympy.core.containersrsympy.core.symbolrrsympy.polys.polyutilsrsympy.plotting.seriesrrsympy.plotting.plotr sympy.utilities.decoratorr sympy.utilities.iterablesr __doctest_requires__r rrrQsQ>(-,L,8-(,8O,EF15| -| r