K i8yddlmZddlmZddlmZmZddlmZddl m Z ddl m Z ddl mZddlmZdd lmZmZmZmZmZmZdd lmZmZmZmZmZdd lmZdd l m!Z!dd l"m#Z#ddl$m%Z%m&Z&ddl'm(Z(ddl)m*Z*ddl+m,Z,ddl-m.Z.m/Z/m0Z0ddl1m2Z2ddl3m4Z4ddl5m6Z6ddl7m8Z8ddl9Z9Gdde*Z:dddddZ;dZdBd"Z?d#Z@Gd$d%e>ZAGd&d'eAZBGd(d)eAZCGd*d+eAZDGd,d-eDZEGd.d/eAZFGd0d1eDZGGd2d3e>ZHGd4d5eHZIGd6d7eHZJGd8d9eIZKGd:d;e>ZLGd<d=e>ZMd>ZNd?ZOdCd@ZPdAZQy)D)Callable)continuous_domain)SumProduct)Tuple)Expr)arity)default_sort_key)Symbol)atan2zetafracceilingfloorim)Equality GreaterThanLessThan RelationalNe)sympify) import_module)BooleanFunction)_get_free_symbolsextract_solution)latex)PythonCodePrinter) precedence)SetIntervalUnion) nsimplify)sympy_deprecation_warning)lambdify)intervalNceZdZdZdZdZy)IntervalMathPrinterzA printer to be used inside `plot_implicit` when `adaptive=True`, in which case the interval arithmetic module is going to be used, which requires the following edits. ct|djfdt|jtDS)Nz & c3BK|]}j|ywN parenthesize.0aPRECselfs [/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sympy/plotting/series.py z1IntervalMathPrinter._print_And..#(B++At4Bkeyrjoinsortedargsr r2exprr1s` @r3 _print_AndzIntervalMathPrinter._print_And!;$zzB /?@BB Bct|djfdt|jtDS)Nz | c3BK|]}j|ywr+r,r.s r3r4z0IntervalMathPrinter._print_Or..(r5r6r7r9r=s` @r3 _print_OrzIntervalMathPrinter._print_Or&r@rAN)__name__ __module__ __qualname____doc__r?rDrAr3r(r(sB BrAr(F)modulesforce_real_evalhas_sumc tdfd j tg d fd }dk(r|S  |gS#t$r}||cYd}~Sd}~wwxYw)zy Note: this is an experimental function, as such it is prone to changes. Please, do not use it in your code. numpyc t||S#ttf$r#tjjcYSwxYwr+)complexZeroDivisionError OverflowErrornan)funcr<nps r3 wrapper_funcz#_uniform_eval..wrapper_func4s@ +4;' '!=1 +266266* * +s /AA)otypesNc:Id}||dz }t||dz }djt|j|t||rEt j dsdnzdjt|j|zdzgS) Nz6Impossible to evaluate the provided numerical function.z,because the following exception was raised: z{}: {}The evaluation with %s failed. NumPy/SciPy{}: {} OTrying to evaluate the expression with Sympy, but it might be a slow operation.)formattyperE RuntimeErrorwarningswarn)errmsgr<f2rJrVs r3_eval_with_sympyz'_uniform_eval.._eval_with_sympy?s :JC{s s# #FFS 2 2C8s# #  MM2)0Mg?!!$s)"4"4c:;'' B&&&rAsympyr+)r vectorizerP Exception) f1rerJrKrLr<rfrcrUrVs `` ` @@r3 _uniform_evalrk,sw w B+<< gY<?L''&'!!%B&&& %$$%sA A(A#A(#A(ctd}||}t|tr|js|j }t |}|j dkDr |jS|jS)a(Evaluate f(x) with an adaptive algorithm. Post-process the result. If a symbolic expression is evaluated with SymPy, it might returns another symbolic expression, containing additions, ... Force evaluation to a float. Parameters ========== f : callable x : float rNg:0yE>) r isinstancer is_NumberevalfrPimagrSreal)fxrUys r3_adaptive_evalru[sX w B !A!TAKK GGI Avv~vv 66MrAcNd}|dk(rd}|S|dk(rd}|S|dk(rd}|S|dk(rd }|S) Nz%srqzre(%s)rpzim(%s)abszabs(%s)argzarg(%s)rI)retwrappers r3_get_wrapper_for_exprr{qsWG f} N  N  N  NrAceZdZdZdZdZdZdZdZdZ dZ dZ dZ dZ dZdZdZdZdZdZdZd Zd Zd,d Zd Zed Zej6dZedZedZdZedZej6dZedZ e j6dZ edZ!e!j6dZ!dZ"edZ#e#j6dZ#edZ$e$j6dZ$edZ%e%j6dZ%e&d-dZ'e&d Z(d!Z)d"Z*d#Z+d.d$Z,ed%Z-e-j6d&Z-ed'Z.e.j6d(Z.d)Z/d*Z0y+)/ BaseSeriesaBase class for the data objects containing stuff to be plotted. Notes ===== The backend should check if it supports the data series that is given. (e.g. TextBackend supports only LineOver1DRangeSeries). It is the backend responsibility to know how to use the class of data series that is given. Some data series classes are grouped (using a class attribute like is_2Dline) according to the api they present (based only on convention). The backend is not obliged to use that api (e.g. LineOver1DRangeSeries belongs to the is_2Dline group and presents the get_points method, but the TextBackend does not use the get_points method). BaseSeries Fdct|jt|}|jdd|_|jdd|_|jdd|_|jdd|_|jdd|_|jd|jd d|_ |jd |jd d|_ d x|_ |_ g|_ t|jd |jt|jd|jt|jd|jg|_|jdd|jdd|jddg|_|jdi|_t'|j$t(s t+dt-|j$dkDrd|_|jdi|_|jdd|_|jdd|_|jdd|_|jdd|_t;d|j2|j4|j6|j8fDs t+dg|_g|_|jdd|_ d|_!d|_"g|_#d|_$d|_%y)N only_integersFrJshow_in_legendTcolorbaruse_cmis_polarpolaris_pointpointn1n2n3xscalelinearyscalezscaleparamsz@`params` must be a dictionary mapping symbols to numeric values.r rendering_kwtxtytztpc3>K|]}t|xs|duywr+callabler/ts r3r4z&BaseSeries.__init__..s$6!8A;-19-6sz)`tx`, `ty`, `tz`, `tp` must be functions.rK)&_set_discretization_pointscopyr_getrrJrrrrr_label _latex_label_rangesint_N_n_scales_paramsrmdict TypeErrorlenis_interactiver_tx_ty_tz_tpall _functions _signature_force_real_eval_discretized_domain_interactive_ranges_needs_to_be_int color_func_eval_color_func_with_signature)r2r<kwargss r3__init__zBaseSeries.__init__s+FKKM4:F#ZZ?zz)T2 %jj)94@  :t4 jj51  :vzz'5/IJ  :vzz'5/IJ *,, d'  4) *  4) *  4) *  JJx * JJx * JJx *  zz(B/ $,,-%& & t|| q "&D #JJ~r:::dD)::dD)::dD)::dD)6 XXtxx488 466GH H!' +.+*qx{*z requires a symbolic expression.N)anyrr_rEr2exprss r3_block_lambda_functionsz"BaseSeries._block_lambda_functions&s: *E* *DJ//3  +rAc |j|j}}|j|j}}t |dr|n|g}t d|Dryt | j|j |" j|Dcgc]}|d c} t dkDrMtddj||||fn||fzdj|zdj zd z|Dcgc]}|d }}|D]}tj|d dDcgc]}|jc} t fd |Drtd t|zt dkDrd |_ j|j}t|dkDstd|dd|zzycc}wcc}wcc}w)zA Checks if there are enough parameters and free symbols. __iter__c32K|]}t|ywr+rrs r3r4z'BaseSeries._check_fs..5rrNrz(Incompatible expression and parameters. zExpression: {} z params: {} z)Specify what these symbols represent: {} zAre they ranges or parameters?r%c3&K|]}|v ywr+rI)r/rfss r3r4z'BaseSeries._check_fs..Ns2q172szWRange symbols can't be included into minimum and maximum of a range. Received range: %sTz)Unknown symbols found in plotting range: z. z Are the following parameters? %s)r>rangesrlabelhasattrrr differencekeysr ValueErrorr^setunion free_symbolsstrr) r2rrrrr range_symbolsr remaining_fsrs @r3 _check_fszBaseSeries._check_fs/s 4;;v TZZ  3% *E* * u % ]]6;;= )  f5!56B r7Q;;$++.4.@UFE*uenVV!''/0?EEbI J 3 3 (..!1. . GAqu=!q~~=>B2M22 !")+.q6"2332w{+/(==7L< 1$ GHJ6EFGG G 6/=s G  G1G c t|jdr |jn |jg}td|Dst|}t |d|_g|_|D]V}|j jt|j ||jt|j |ddgXnEt |jDcgc]}|d  c}d |_|Dcgc]}|d fc}|_t|jtr-t|j |j|_ d|_y y cc}wcc}w) aCreate the lambda functions to be used by the uniform meshing strategy. Notes ===== The old sympy.plotting used experimental_lambdify. It created one lambda function each time an evaluation was requested. If that failed, it went on to create a different lambda function and evaluated it, and so on. This new module changes strategy: it creates right away the default lambda function as well as the backup one. The reason is that the series could be interactive, hence the numerical function will be evaluated multiple times. So, let's create the functions just once. This approach works fine for the majority of cases, in which the symbolic expression is relatively short, hence the lambdification is fast. If the expression is very long, this approach takes twice the time to create the lambda functions. Be aware of that! rc32K|]}t|ywr+rrs r3r4z1BaseSeries._create_lambda_func..ts.18A;.rc|jSr+namers r3z0BaseSeries._create_lambda_func..vs qvvrAr7)rJrgT)rJdummifyrc|jSr+rrs r3rz0BaseSeries._create_lambda_func..s PQPVPVrAN)rr>rrr;rrappendr$rJrrmrrr)r2rrrrs r3_create_lambda_funczBaseSeries._create_lambda_func^s*%TYY ; $))..."5)B$R-=>DO !DO &&T__aFT__a$O( %DKK%@qad%@FVWDO278Q4y8DO doot ,&tHDO37D 0 - &A8s  E5 Ecx|js t|St|j|jS)zIf the value of a plotting range is a symbolic expression, substitute the parameters in order to get a numerical value. )rrPsubsr)r2rs r3_update_range_valuezBaseSeries._update_range_values/''1: qvvdkk*++rAcg}g}t|jD]L\}}|j|d|j|d}|j|d}|j|jcxk(rdk(rnn |j n|}|j|jcxk(rdk(rnn |j n|}|j xs|d|jv} tj|||j||j|| } |js#| s!| jdk7r| d|jzz} | r| jt} |j| O|j!||y)z?ARWWQXXg./?E?!!!!#F @s D,9+D1crg}|jD]}||jjvri|j||jvrt |j|n2|j r|j|nt|j||j|j||S)zuCreate a list of arguments to be passed to the lambda function, sorted according to self._signature. ) rrrrrrrrPr)r2r<rs r3rzBaseSeries._aggregate_argss 9ADLL%%'' ,-1F1F,FC Q('+'<'zBaseSeries.exprszzrAct|d}|s t|ntd|D}|r||_y|s t |nt ||_t }|jjttD]>}|jddD]*}t|dts|j|d,@t||_t t"t$t&t(g}|j*dur|Dcgc]}|jj-|}}t||_|j*rp|j.(t|j.t0rJd|j.vr.s9Q!(1+9Qrr%NTrNzqNumPy is unable to evaluate with complex numbers some of the functions included in this symbolic expression: %s. zHence, the evaluation will use real numbers. If you believe the resulting plot is incorrect, change the evaluation module by setting the `modules` keyword argument.)rrrr rrratomsrrr<rmr addlistrrrr rr rhasrJrrrarbrr) r2ris_iter is_callablerr0pfrr check_rescfuncss r3r>zBaseSeries.exprs!Z()0hqkc9Qq9Q6Q DJ+2q DJAZZ%%c73 %%A!!B%0ae % %%)GD !5%t4B$$D08:;1TZZ^^A.; ;(+I%((t||/C c2w$,,7N+.r9+=C41aQCECMM#46;#<6#67((*<Ds<"G ? G Gc^|j|j|jg}t|Sr+) is_3Dlinerrr)r2flags3Ds r3is_3DzBaseSeries.is_3D&s(>>4#4#4d6F6FG7|rAcH|j|jg}t|Sr+) is_2Dlinerr)r2 flagsliness r3is_linezBaseSeries.is_line+snndnn5 :rAct|||t|st|tr||_t||dy|d|_yy)z>This method enables back-compatibility with old sympy.plottingN)setattrrrmrr)r2propvals r3_line_surface_colorzBaseSeries._line_surface_color0sD dC C=JsD1!DO D$ % _"DOrAc|jSr+) _line_colorrs r3 line_colorzBaseSeries.line_color<srAc(|jd|y)Nr*r(r2r's r3r+zBaseSeries.line_color@s   4rAc|jS)zIReturns a list [n1, n2, n3] of numbers of discratization points. )rrs r3rz BaseSeries.nDs wwrAct|ds||jd<n||jdt||jr|j yy)aSet the numbers of discretization points. ``v`` must be an int or a list. Let ``s`` be a series. Then: * to set the number of discretization points along the x direction (or first parameter): ``s.n = 10`` * to set the number of discretization points along the x and y directions (or first and second parameters): ``s.n = [10, 15]`` * to set the number of discretization points along the x, y and z directions: ``s.n = [10, 15, 20]`` The following is highly unreccomended, because it prevents the execution of necessary code in order to keep updated data: ``s.n[1] = 15`` rrN)rrrrrr2vs r3rz BaseSeries.nJsI$q*%DGGAJ DGGGSV   # #  + + - $rAc|jS)zGet or set the current parameters dictionary. Parameters ========== p : dict * key: symbol associated to the parameter * val: the numeric value rrs r3rzBaseSeries.paramsds||rAc||_yr+r4)r2ps r3rzBaseSeries.paramsrs  rAct|jdr |jn |jg}td|Dr|jr t dtd|Dr)|j t |jk(rd|_|jt|dr7|jr*|jrtjdd|_ yyyy) Nrc32K|]}t|ywr+rrs r3r4z(BaseSeries._post_init..xrrz`params` was provided, hence an interactive plot is expected. However, interactive plots do not support user-provided numerical functions.c32K|]}t|ywr+rrs r3r4z(BaseSeries._post_init..rrradaptivez`params` was provided, hence an interactive plot is expected. However, interactive plots do not support adaptive evaluation. Automatically switched to adaptive=False.F) rr>rrrrrrrr:rarbrs r3 _post_initzBaseSeries._post_initvs$TYY ; $)) *E* *t{{56 6 *E* *{{c$))n,   4 $4;; MM" #"DM ?Jdoo& A:~~$"4"4t9>..ttAw/GaQQ**4??47+CT!WMMD$6$6**4??47+CT!WMM""t'9'9**4??47+CT!WMM&&ttAw'?aI I aZ  T%7%7**?4??DH+EtAwOO&&tRa'A47K K""?4??D%L#A47KKrAct)zCompute and returns the numerical data. The number of parameters returned by this method depends on the specific instance. If ``s`` is the series, make sure to read ``help(s.get_data)`` to understand what it returns. )NotImplementedErrorrs r3get_datazBaseSeries.get_data*s "!rAc ||zS)zGiven a latex representation of an expression, wrap it inside some characters. Matplotlib needs "$%s%$", K3D-Jupyter needs "%s". rI)r2rrzs r3_get_wrapped_labelzBaseSeries._get_wrapped_label3srAc|dur |jS|jt|jk(r|j|j|S|jSaReturn the label to be used to display the expression. Parameters ========== use_latex : bool If False, the string representation of the expression is returned. If True, the latex representation is returned. wrapper : str The backend might need the latex representation to be wrapped by some characters. Default to ``"$%s$"``. Returns ======= label : str F)rrr>rarr2 use_latexrzs r3 get_labelzBaseSeries.get_label9sQ  ;;  ;;#dii. (**4+<+rAc g}|D]6}||jt|Dcgc] }t|c}8||_ycc}wr+)rtuplerr)r2r'new_valsr2rs r3rzBaseSeries.rangescsK @A}1&=awqz&= >? @  '>sAc d}d\}}}t|dk(r+|\}}|||j|||jfSt|dk(rNt|tr>|\}}}|||j|||j|||j fSt|dk(r>|\}}}|||j|||j|||j fSt|dk(rat|trQ|\}}}}|||j|||j|||j |||j fSt|dk(rQ|\}}}}|||j|||j|||j|||jfSt|dk(rRt|trB|\}}}}}|||j|||j|||j ||fSt|dk(r|jrw|\}}}}}}|||j|||j|||j |||j|||j|||j fSt|dk(r"|\}}} } } } |||| |j | | | fS|S)a'Apply transformations to the results of numerical evaluation. Parameters ========== args : tuple Results of numerical evaluation. Returns ======= transformed_args : tuple Tuple containing the transformed results. c||S||Sr+rIrs transforms r3rz-BaseSeries._apply_transform..xsi&7Yq\rA)NNNrrS) rrrrmParametric2DLineSeriesrrParametric3DLineSeriesParametricSurfaceSeriesr) r2r<rrsrtzur2w_abs_argimgcolorss r3_apply_transformzBaseSeries._apply_transformks J"1a t9>DAqQ>1Q>1 1$i1n*T3I"JGAq!aNAaNAaNC C Y!^GAq!Q>1Q>1Q>A A$i1n*T3I"JJAq!QaNAaNAaNAaNS S Y!^JAq!Q!TXX!TXX!TXX!TXX $i1n*T3J"K MAq!QaNAaNAaNAqI I$i1n$"2"2# Aq!Q1!TXX!TXX!TXX!TXX!TXX!TXX Y!^,0 )Aq$c61adhh'sF< < rAcd\}}|jr1d}dtt|jj z}||z|zS)N)rr interactive  and parameters )rrrkrr)r2rpreposts r3 _str_helperzBaseSeries._str_helpersH T    C%E$++2B2B2D,E(FFDQw~rAN)T)rFFz$%s$)1rErFrGrHr!rr is_contourrrrW is_generic is_vector is_2Dvectorrrrrrrrrrr rpropertyr>setterrr#r(r+rrr;rrCr staticmethodrrr\r_rarfrrr~rrIrAr3r}r}~s.I I L J KNM JIKK B\5|-G^,8\,OBD."@  [[#+#+J #  55 XX..2   ]]". ]]&& ##88"" " "++*  D>L@" !0   \\.. ]]  .`rAr}cPtd}|j}|jdz |z }tt |dz D]\} || dz|| z } t || dz|| z } |j | | z } t | |k\sK|j|| dz<^||fS)a<Compute the steepness of each segment. If it's greater than a threshold, set the right-point y-value non NaN and record the corresponding x-location for further processing. Returns ======= x : np.ndarray Unchanged x-data. yy : np.ndarray Modified y-data with NaN values. rNrr%)rrpirangerrwarctanrS) rsrtepsr>symbsymbolicrUyy thresholdrdxdyangles r3_detect_poles_numerical_helperrs w B B CI 3q6A:  q1uX!_ 1q5AaD ! "r'" u: "Bq1uI  b5LrAcg}tt|t|}t|||}|j}||k(r |St |t rt d|jDrxg}|jD]Q}|jr|j|j|js7|j|jStt|}|Std|d)zAttempts to compute symbolic discontinuities. Returns ======= pole : list List of symbolic poles, possibly empty. c3<K|]}t|tywr+)rmr rs r3r4z0_detect_poles_symbolic_helper..s 6Jq( # 6sz&Could not parse the following object: zJ . Please, submit this as a bug. Consider also to set `detect_poles=True`.)r r"rsimplifyrmr!rr< left_openrleft right_openrightrrr)r>rrrpolesr&resrs r3_detect_poles_symbolic_helperrs E %()C.9H D$ 1C ,,.C h L S%  6SXX 66 &A{{ QVV$|| QWW%  & SZ  L 4SE:# #  rAceZdZdZdZdZdZfdZdZdZ dZ e d Z e d Z e d Ze d Zej d ZdZxZS)Line2DBaseSerieszA base class for 2D lines. - adding the label, steps and only_integers options - making is_2Dline true - defining get_segments and get_color_array Tric t|di||jdd|_|jd|jdd|_|jd|jdd|_|jdd|_|jd d |_|jd d|_|jd d|_ |jd d|_ |jdd|_ |jdd|_ |jd|jdd|_ |jdd|_g|_|jdg}t!|t"rt%t'|d}t)|ds|g}|Dcgc] }t+|}}t-||_ycc}w)NstepsFrr is_filledfillTr:depth rrr+ detect_polesr{Gz?rrunwrapexcluder~rrrI)superrrrrrr:rrrr+rrrrpoles_locationsrmrrrrfloatr;r)r2rrr __class__s r3rzLine2DBaseSeries.__init__s{ "6"ZZ/  :vzz'5/IJ KFD1IJ :u5 ZZ, jj51  **\48 **\48"JJ~u=::eT* :vzz'5/IJ jj51  "**Y+ gs #+Gs;.s)*;Q1rArTr%NrrS)r_get_data_helperrmLineOver1DRangeSeriesrrr>rrrrrrrr~r!rrrrrTflattenrWrrepeatr_insert_exclusions) r2rUpointsrrrsrtr6kwrws r3r_zLine2DBaseSeries.get_datas*7 #&&( t2 3   * ,1 t{{+>.2kk!n>EHH61eAh67EMA#$RXXe_dhh#?D '&&/ >>d//6{a15q$(($1Q 1a5aDHHE1Q ;;B{{$&[[~~v;!#!DAq! !*r*AVF$GAq!! !*r*AAYF :: ~~ay&)1HHaV$&&..04HHaV$&&..0"5%%F1I.FVFIIfQi+AB/IIfQi+CR0IIfQi+Ab1v;?Avay1FAYF t|| q ,,V4F i7sK:c2tdddtd}t|j|}|jj |j jdd|j}|jj|dd|ddgdS) Nz The Line2DBaseSeries.get_segments() method is deprecated. Instead, use the MatplotlibBackend.get_segments() method, or use The get_points() or get_data() methods. z1.9zdeprecated-get-segments)deprecated_since_versionactive_deprecations_targetrNrr%)axis) r#rr_r_marrrP_dim concatenate)r2rUrs r3 get_segmentszLine2DBaseSeries.get_segmentsTs!  &+'@ B7 #d$$T*V$&&..r1dii@uu  &"+vabz!: CCrAc ltd}t|}t|}|dz }|dk(rd}tt t |j |g}|jDcgc]}|d }}|jD](}|||z dk\} t| st| s(|j| } | dz} | dkDsD| t||dz ksYt|||| z } t|||| dzz } t| | dz } || z }|| z}|j||d| |||g||| dzdf||<d}|D]\}|||j||g}|dz }|j||d| |d|j|dg||| dzdf||<^+|Scc}w)aqAdd NaN to each of the exclusion point. Practically, this adds a NaN to the exclusion point, plus two other nearby points evaluated with the numerical functions associated to this data series. These nearby points are important when the number of discretization points is low, or the scale is logarithm. NOTE: it would be easier to just add exclusion points to the discretized domain before evaluation, then after evaluation add NaN to the exclusion points. But that's only work with adaptive=False. The following approach work even with adaptive=True. rNr%rrr~N)rrrr;rrrrrr nanargmaxrwminrrrS)r2rrUrk j_indecesrrrrridx delta_prev delta_postdeltaprevrrjvaluess r3rz#Line2DBaseSeries._insert_exclusionsds7 #f K E 6A3uQx=33QC89 #/!1// bA)a-1$C3xCIll3'q7sS^a%77!$Q3%7!8J!$Q37);%;!!$ $ % 0A Ac|jsy |j|jddS#t$r|jddcYSwxYwNrrrrs r3rzLine2DBaseSeries.endrrc |jdSr@r=rs r3rzLine2DBaseSeries.xscales||ArAc||_yr+)rr1s r3rzLine2DBaseSeries.xscale  rActd}|j}t|dr|j|}t |}|dk(r-|j r!|j }|t|Sttt|j}|dk(r ||dS|dk(r||ddS||S||j|jzS)NrN__call__r%rr) rr+rrhr rWget_parameter_pointscenters_of_segmentsrmap get_pointsones nb_of_points)r2rUrrrr[rs variabless r3get_color_arrayz Line2DBaseSeries.get_color_arrays 7 # OO 1j ! QA!HEzd00--/,Q/00 %8$//:K!LM A:Yq\?*aZim,,i=(RWWT..// /rA)rErFrGrHr!rrrr_rrrrrrrrr __classcell__rs@r3rrsI D B'2PdD 4l>>%%%% ]]0rArc6eZdZdZdfd ZdZdZdZxZS) List2DSeriesz7Representation for a line consisting of list of points.c @t|di|tdt|t|k7r>t dj t|dj t|z|j ||d}t||||zs |jr2|js t dt||_ t||_ nDj|j|_ j|j|_ |j|jf|_tfd|j|jfDs|j|j!d|j!d d |_||_|j!d i|_|j(rT|j*rGd |_t/|j*t0r%t3d |j4j6zdzyyy)NrNz_The two lists of coordinates must have the same number of elements. Received: len(list_x) = {} zand len(list_y) = {}cf|Dcgc]!}t|txr |j #c}Scc}wr+)rmr is_number)lrs r3rz'List2DSeries.__init__..s)aP:a.D ODPPs&.zSome or all elements of the provided lists are symbolic expressions, but the ``params`` dictionary was not provided: those elements can't be evaluated.rc3JK|]}t|jywr+)rmrM)r/rrUs r3r4z(List2DSeries.__init__..sQ:a,Qs #rrFrTz%s don't support symbolic zexpression for `color_func`.rI)rrrrrr^rrrrlist_xlist_yrfloat64r rrrrrrrrWrmrrrrE)r2rrrrcheckrUrs @r3rzList2DSeries.__init__s "6" 7 # v;#f+ %..4fS[.A&--c&k:;  $$VV4P uV}uV}, -;; "KLL .DK.DK((6(>3J3JJ23441+;rAcy)Nz 2D list plotrIrs r3__str__zList2DSeries.__str__srAc|j|j}}|js|j||St d}|j |Dcgc]}|j |j c}t}|j |Dcgc]}|j |j c}t}|j||Scc}wcc}w)3Returns coordinates that needs to be postprocessed.rN)rr) rrr_eval_color_func_and_returnrrrorr)r2lxlyrUrs r3rzList2DSeries._get_data_helpersdkkB""33B; ; 7 # XX"=QqwwDKKw0=UX K XX"=QqwwDKKw0=UX K//B77>=s #C#Ccn|jr(t|jrg||j|S|Sr+)rrrr\r2datas r3rz(List2DSeries._eval_color_func_and_returns7 ;;8DOO47T7/4//67 7 rAr) rErFrGrHrrrrrrs@r3rrsA"4H 8rArc|eZdZdZd fd ZedZejdZdZdZ dZ dZ d Z d Z xZS) rzHRepresentation for a line consisting of a SymPy expression over a range.c t|di|t|r|n t||_|t |jn||_|t|jn||_|g|_ t|_ |jdd|_ |j|jsh|jdddDcgc] }t|c}\}}t!|t!|k7r%t#d|j$j&zdz|j(r*|jrt+j,dd|_yyycc}w) Nreturnrr%z%s requires the imaginary z=part of the start and end values of the range to be the same.zjThe adaptive algorithm is unable to deal with complex numbers. Automatically switching to uniform meshing.FrI)rrrrr>rrrrrrPrr_returnr;rrrrrEr:rarb) r2r> var_start_endrrrrrrs r3rzLineOver1DRangeSeries.__init__ s! "6"$TND  (- c$))n5 05 E$)),5$o  zz(D1  ''/3kk!nQR.@A'!*AJE3%yBsG# 04>>3J3JJ&&'' ==T\\ MMO P!DM*=BsEc |jdSr@rrs r3rz"LineOver1DRangeSeries.nb_of_points'vvayrAc||_yr+rr1s r3rz"LineOver1DRangeSeries.nb_of_points+ rAc d}|jrdnd}d}|jr/dtt|jj z}t |j }|d||jzdt|jdt||j||jfz|zS)Nc`t|tr|jdk7r|S|jS|Sr@)rmrPrprqrs r3rrz(LineOver1DRangeSeries.__str__..f0s*!W%66Q;Hvv HrArrrzcartesian line:  for  over ) rrrkrrr{rr>rrr)r2rrrrrzs r3rzLineOver1DRangeSeries.__str__/s  !% 3 3n   %E$++2B2B2D,E(FFD' 5 dii  M 4::$(( , -     rAc"|jS)aReturn lists of coordinates for plotting. Depending on the ``adaptive`` option, this function will either use an adaptive algorithm or it will uniformly sample the expression over the provided range. This function is available for back-compatibility purposes. Consider using ``get_data()`` instead. Returns ======= x : list List of x-coordinates y : list List of y-coordinates rrs r3rz LineOver1DRangeSeries.get_pointsAs $$&&rAc   t|jr |j}n,t|jg|j|j}|j |\}}||fS#t $r}tjd|jsdn |jzdjt|j|zdzt|jg|jd}|j |\}}Yd}~||fSd}~wwxYwNrZr[r\r]rg) rr>r$rrJ_adaptive_sampling_helperrirarbr^r_rE)r2rrrsrtrcs r3_adaptive_samplingz(LineOver1DRangeSeries._adaptive_samplingSs 5 "IIdhhZDLLA11!4DAq!t  5 MM2)-M4<<I!!$s)"4"4c:;'' $((TYY8A11!4DAq!t  5sA"A(( D 1BDD ctdggfdtjj}tjj}j jjj |j jj|gj jj|gdfS)aZThe adaptive sampling is done by recursively checking if three points are almost collinear. If they are not collinear, then more points are added between those points. References ========== .. [1] Adaptive polygonal approximation of parametric curves, Luiz Henrique de Figueiredo. rNcFd jjdzz} jdk(rEd j|d| j|d j|dz zzz}n|d||d|dz zz}t |} j ||g}| j kDr)j|dj|dy|dkr |||dz |||dzy|d|d jdk(r j|d|dd}n j|d|dd}tt |}td |DsNtt|dz D]3} ||  || dz || || g|| dz|| dzg|dz5yy|d|d|d t|||s |||dz |||dzyj|dj|dy) Samples recursively if three points are almost collinear. For depth < 6, points are added irrespective of whether they satisfy the collinearity condition or not. The maximum depth allowed is 12. ?皙?log rr%rsNc3$K|]}|du ywr+rI)r/rts r3r4zRLineOver1DRangeSeries._adaptive_sampling_helper..sample..s5195s)randomrandrlog10rurrrlogspacerIrrrrrflat)r6qrr xnewynew new_pointxarrayyarrayrrrrUsampler2x_coordsy_coordss r3r+z?LineOver1DRangeSeries._adaptive_sampling_helper..sampleusTBIINN,s22F{{e#BHHQqTNVrxx!~8:18G.HHItf!qt 44!!T*D$.Itzz!!%!%q)UQY/y!UQY/ 1!A$,;;%'[[1qtR8F[[1qtR8Fc!Vn-5f55"3v;?3K &q 1fQUm6K"F1Ivay#9!'Aq1u > KK6A$,!A$,)A,2F9a0q)UQY/y!UQY/!%!%rAr)rrurrqrrr)r2rrf_startf_endrUr+r,r-s`` @@@@r3rz/LineOver1DRangeSeries._adaptive_sampling_helperfs7 #2 &2 &h!DJJOO4q$((--0 ( rxx'23$((--/0! 5(##rActd}|j\}}|j||j|}}|j ||}|j ||}|||fSNrN)rr rqrpr)r2rUrsresultrYrZs r3_uniform_samplingz'LineOver1DRangeSeries._uniform_samplingse 7 #NN$ 6776?BGGFOS!!#q)!!#q)#s{rAc td}|jr@|js4|j\}}||fDcgc]}|j |c}S|j \}}}|j A|j||j|j||j|<||fS|j dk(r ||fS|j dk(r|}||fS|j dk(r|j|dz|dzz}||fS|j dk(r|j||}||fStd|j zcc}w)z ?#v \\V # #v \\V #C#v \\U "''#q&36/*C#v \\U "**S#&C #v !%./ /#1sE r)rErFrGrHrrrrrrrrr3rrrs@r3rr sYR"6$'$&J$XrArcjeZdZdZdZd dZdZdZdZdZ e dZ e jd Z y ) ParametricLineBaseSeriesTc|t|jn||_|t|jn||_|j durV|jt|jk(r4t|j |_t|j |_td|j Dr8|j s+|jt|j k(rd|_yyyy)aULogic to set the correct label to be shown on the plot. If `use_cm=True` there will be a colorbar, so we show the parameter. If `use_cm=False`, there might be a legend, so we show the expressions. Parameters ========== label : str label passed in by the pre-processor or the user NFc32K|]}t|ywr+rrs r3r4zFParametricLineBaseSeries._set_parametric_line_label..s.qx{.rr)rrrrrrr>r)r2rs r3_set_parametric_line_labelz3ParametricLineBaseSeries._set_parametric_line_labels(-}c$((m% /4}E$((O% KK5 t{{c$((m'Cdii.DK %dii 0D  .DII. . {{c$))n,  -9D .rAc|jrjt|j|jk(r<|r%|j t |j|St|jS|jS|rJ|jt|j k7r |jS|j |j|S|jSr+)rrrrrarr>rrds r3rfz"ParametricLineBaseSeries.get_labels ;;488} +225?GLL488}$;;  {{c$))n,(((**4+<+>dmmw'BGAq!1q!t $A 1a AF2J'F DOO $&\F---v6F2J !3sC(c >td}|j}t|D]i\}}|j||j |}}|j ||j |j||j|<|||<kg|dd|dS)rrNr%Nr) rr rrqrprSrTrUrV)r2rUr rrrYrZs r3r3z*ParametricLineBaseSeries._uniform_samplings 7 #.."g& DAqwwqz2771:CBD&&C "**S"--*<=> ?GAJ  *)gaj))rAc(|jdS)Nrr_rs r3rz-ParametricLineBaseSeries.get_parameter_points)s}}r""rAc(|jddS)aJ Return lists of coordinates for plotting. Depending on the ``adaptive`` option, this function will either use an adaptive algorithm or it will uniformly sample the expression over the provided range. This function is available for back-compatibility purposes. Consider using ``get_data()`` instead. Returns ======= x : list List of x-coordinates y : list List of y-coordinates z : list List of z-coordinates, only for 3D parametric line plot. Nrrrs r3rz#ParametricLineBaseSeries.get_points,s"$$&s++rAc |jdSr@rrs r3rz%ParametricLineBaseSeries.nb_of_points?r rAc||_yr+rr1s r3rz%ParametricLineBaseSeries.nb_of_pointsCr rANr) rErFrGrWr;rfrr3rrrrrrIrAr3r8r8sSM!,"6 *#,&rAr8c:eZdZdZdZdfd ZdZdZdZxZ S)rtzZRepresentation for a line consisting of two parametric SymPy expressions over a range.Tc ht|di|t|r|n t||_t|r|n t||_|j|j f|_|g|_t|_ |jdd|_ |j||jy)NrTrI)rrrrexpr_xexpr_yr>rrrrrr;r;)r2rHrIr rrrs r3rzParametric2DLineSeries.__init__Ns "6" ( 0fgfo ( 0fgfo [[$++. $o  jj40  ''. rAc |jdt|jdt|jdt|jdt|j |j fS)Nzparametric cartesian line: (, ) for r)rrrHrIrrrrs r3rzParametric2DLineSeries.__str__YsR     M TXX& '    rAc  t|jr.t|jr|j}|j}nBt|jg|j}t|jg|j}|j ||\}}}|||fS#t $r}tjd|jsdn |jzdjt|j|zdzt|jg|jd}t|jg|jd}|j ||\}}}Yd}~d}~wwxYwr) rrHrIr$rrrirarbrJr^r_rE)r2f_xf_yrsrtr6rcs r3rz)Parametric2DLineSeries._adaptive_samplingbs* ? $$++)>kkkkz4;;7z4;;744S#>GAq!!Qw ? MM2)-M4<<I!!$s)"4"4c:;'' DHH:t{{GGAq! ?sBB"" E(+B3E##E(c g g g  fd tj}tj}||g}tj}tj}||g} j| j| jj jj||d fS)aWThe adaptive sampling is done by recursively checking if three points are almost collinear. If they are not collinear, then more points are added between those points. References ========== .. [1] Adaptive polygonal approximation of parametric curves, Luiz Henrique de Figueiredo. c dtd}d|jjdzz}||||z zz}t|}t|} |j || g} |j kDr:j |dj |dj |y|dkr|||| |dz||| ||dzy|d|d |d|d|j||d} | D cgc]} t| } } | D cgc]} t| }} td t| |Dshtt|dz D]M}| |||| |dz||dz| |||g}| |dz||dzg}| || ||||dzOyy|d|d|d|d t|| |s|||| |dz||| ||dzyj |dj |dj |ycc} wcc} w) rrNrrrr%rsNrc36K|]\}}|duxr|duywr+rI)r/rsrts r3r4zSParametric2DLineSeries._adaptive_sampling_helper..sample..s,>#q!92d2>s) rr r!rurrrrIrrrrr$)param_pparam_qr6r%rrUr  param_newr&r'r( param_arrayrx_arrayy_arrayrpoint_apoint_brNrOparamr+r2r,r-s r3r+z@Parametric2DLineSeries._adaptive_sampling_helper..samplesw'BBIINN,s22F&Gg,=">>I!#y1D!#y1D$.Itzz!!%!% W%w 1iCy'9aC Q4#q1GG;FGa>#q1GG>'*7G'<>>"3wG'.q1u~wq1u~&FG";q>;q>7#*EAI7 7>A$,!A$,t|qt|9a0w 1iCy'9aC!%!% W%-HGs ;H(H-r)rurrr) r2rNrO f_start_x f_start_yrf_end_xf_end_yrr[r+r,r-s ``` @@@@r3rz0Parametric2DLineSeries._adaptive_sampling_helperxs6 &6 &p#3 3 "3 3 I& dhh/ dhh/  " " TZZ tzz488UC35((rAr) rErFrGrHr!rrrrrrs@r3rtrtHs$I  ,R)rArtc.eZdZdZdZdZdZfdZxZS)Line3DBaseSerieszSA base class for 3D lines. Most of the stuff is derived from Line2DBaseSeries.FTrSc"t|yr+)rr)r2rs r3rzLine3DBaseSeries.__init__s rA) rErFrGrHr!rrrrrs@r3raras#;II DrArac<eZdZdZdZdZdfd ZdZfdZxZ S)ruz^Representation for a 3D line consisting of three parametric SymPy expressions and a range.FTc t|di|t|r|n t||_t|r|n t||_t|r|n t||_|j|j |j f|_|g|_t|_ d|_ |jdd|_ |j||jd|_d|_d|_y)NFrTrI)rrrrrHrIexpr_zr>rrrr:rrr;r;_xlim_ylim_zlim)r2rHrIrer rrrs r3rzParametric3DLineSeries.__init__s "6" ( 0fgfo ( 0fgfo ( 0fgfo [[$++t{{; $o   jj40  ''.    rAc|jdt|jdt|jdt|jdt|j dt|j |jf S)Nz3D parametric cartesian line: (rKrLr)rrrHrIrerrrrs r3rzParametric3DLineSeries.__str__s^       M TXX& '    rAc6td}t| \}}}}|j||j |f|_|j||j |f|_|j||j |f|_||||fSr1)rrr_aminamaxrfrgrh)r2rUrsrtrwr6rs r3r_zParametric3DLineSeries.get_datas 7 #W%' 1aggaj"''!*- ggaj"''!*- ggaj"''!*- !QzrAr) rErFrGrHr!rrrr_rrs@r3rurus( II" rAruc2eZdZdZdZfdZdZdZxZS)SurfaceBaseSerieszA base class for 3D surfaces.TcZt|di||jdd|_|jd|jdd|_|jdd|_|jdd|_t|j r|j |_d|_yy) NrFrrrCrc|Sr+rI)rsrtrws r3rz,SurfaceBaseSeries.__init__..s1rArI)rrrrrrCrrr2r<rrs r3rzSurfaceBaseSeries.__init__ s "6"jj51  :vzz'5/IJ #ZZ> **\3DE D&& '"00DO!%D  (rAc|j}| t|n||_| t|n||_t |ds t |ntd|D}|r(|jt|k(rd|_d|_yyy)Nrc32K|]}t|ywr+rrs r3r4z7SurfaceBaseSeries._set_surface_label..&s0QXa[0rr)r>rrrrrrr)r2rr is_lambdas r3_set_surface_labelz$SurfaceBaseSeries._set_surface_labels{ $)Mc%ju ,1ME%Lu-4E:,FXe_0%00  $++U3  $&!49rActd}|j}t|tr|j |}t |}|j rAttt|j}|dk(r ||dS|dk(r||Sttt|j}|dk(r ||dS|dk(r||ddS||St|tr2||jt|j|j zS||jt|j"|j$zS)NrNr%rr)rrCrmrrhr rWrrcenters_of_facesget_parameter_meshes get_meshesSurfaceOver2DRangeSeriesrrnb_of_points_xnb_of_points_ynb_of_points_unb_of_points_v)r2rUrrrr[rs r3rz!SurfaceBaseSeries.get_color_array+s* 7 #    a " QA!HE!! %5t7P7P7R!ST A:Yq\?*aZi=(S!14??3DEFIz1&!)BQ-(()}$$ 89T%8%8$:M:M!NOOOT%8%8$:M:M!NOOOrA) rErFrGrHrrrurrrs@r3rnrns'L&" 'PrArnceZdZdZdfd ZedZedZedZedZ edZ edZ ed Z e jd Z ed Zejd Zd ZdZdZxZS)rzzRRepresentation for a 3D surface consisting of a SymPy expression and 2D range.c &t|di|t|r|n t||_||g|_|j ||j|j|jf|_ |j|jf|_ y)NrI)rrrrr>rrur;start_xend_xrfstart_yend_yrg)r2r>var_start_end_xvar_start_end_yrrrs r3rz!SurfaceOver2DRangeSeries.__init__Isr "6"$TND  &8  & llDJJ/ llDJJ/ rAc&|jddSr@rrs r3var_xzSurfaceOver2DRangeSeries.var_xS{{1~a  rAc&|jddSNr%rrrs r3var_yzSurfaceOver2DRangeSeries.var_yWrrAc| t|jddS#t$r|jddcYSwxYwrrrrrs r3rz SurfaceOver2DRangeSeries.start_x[A %Q*+ + %;;q>!$ $ % ;;c| t|jddS#t$r|jddcYSwxYwrrrs r3rzSurfaceOver2DRangeSeries.end_xbrrc| t|jddS#t$r|jddcYSwxYwNr%rrs r3rz SurfaceOver2DRangeSeries.start_yirrc| t|jddS#t$r|jddcYSwxYwNr%rrrs r3rzSurfaceOver2DRangeSeries.end_yprrc |jdSr@rrs r3r{z'SurfaceOver2DRangeSeries.nb_of_points_xwr rAc4|j}||ddg|_yrrr2r2rs r3r{z'SurfaceOver2DRangeSeries.nb_of_points_x{ FFQqrUrAc |jdSrrrs r3r|z'SurfaceOver2DRangeSeries.nb_of_points_yr rAc<|j}|d||dg|_yrrrs r3r|z'SurfaceOver2DRangeSeries.nb_of_points_y FFA$1Q4rAcV|jrdnd}|j|dt|jdt|jdt|j |j fdt|jdt|j|jf zS)Nzcartesian surfacecontourz: rr and ) rrrr>rrrrrr)r2 series_types r3rz SurfaceOver2DRangeSeries.__str__s{-1->->)I    N  OS$,, !;<  OS$,, !;<    rAc"|jS)Return the x,y,z coordinates for plotting the surface. This function is available for back-compatibility purposes. Consider using ``get_data()`` instead. rBrs r3ryz#SurfaceOver2DRangeSeries.get_meshess }}rAc Ftd}|j}t|D]i\}}|j||j |}}|j ||j |j||j|<|||<k|\}}} |jrD|jr8|j}||j|z}||j|z}|j| |j| f|_|j#||| S)aReturn arrays of coordinates for plotting. Returns ======= mesh_x : np.ndarray Discretized x-domain. mesh_y : np.ndarray Discretized y-domain. mesh_z : np.ndarray Results of the evaluation. rN)rr rrqrprSrTrUrVrrrcossinrkrlrhr~ r2rUr rrrYrZrsrtrws r3r_z!SurfaceOver2DRangeSeries.get_datas7 #.."g& DAqwwqz2771:CBD&&C "**S"--*<=> ?GAJ  1a ==T..ABFF1I ABFF1I Aggaj"''!*- $$Q1--rAr)rErFrGrHrrrrrrrrr{rr|rryr_rrs@r3rzrzEs0!!!!%% %% %% %% !! .rArzc eZdZdZdZ dfd ZedZedZedZ edZ edZ ed Z ed Z e jd Z ed Zejd ZdZdZdZdZxZS)rvzaRepresentation for a 3D surface consisting of three parametric SymPy expressions and a range.Tc t|di|t|r|n t||_t|r|n t||_t|r|n t||_|j|j |j f|_||g|_|jdd|_ |j||jy)Nrc|Sr+rI)rsrtrwrxr2s r3rz2ParametricSurfaceSeries.__init__..srArI) rrrrrHrIrer>rrrrur;) r2rHrIrevar_start_end_uvar_start_end_vrrrs r3rz ParametricSurfaceSeries.__init__s "6" ( 0fgfo ( 0fgfo ( 0fgfo [[$++t{{; &8  **\3JK & rAc&|jddSr@rrs r3var_uzParametricSurfaceSeries.var_urrAc&|jddSrrrs r3var_vzParametricSurfaceSeries.var_vrrAc| t|jddS#t$r|jddcYSwxYwrrrs r3start_uzParametricSurfaceSeries.start_urrc| t|jddS#t$r|jddcYSwxYwrrrs r3end_uzParametricSurfaceSeries.end_urrc| t|jddS#t$r|jddcYSwxYwrrrs r3start_vzParametricSurfaceSeries.start_vrrc| t|jddS#t$r|jddcYSwxYwrrrs r3end_vzParametricSurfaceSeries.end_vrrc |jdSr@rrs r3r}z&ParametricSurfaceSeries.nb_of_points_ur rAc4|j}||ddg|_yrrrs r3r}z&ParametricSurfaceSeries.nb_of_points_urrAc |jdSrrrs r3r~z&ParametricSurfaceSeries.nb_of_points_vr rAc<|j}|d||dg|_yrrrs r3r~z&ParametricSurfaceSeries.nb_of_points_vrrAc|jdt|jdt|jdt|jdt|j dt|j |jfdt|jdt|j|jfS)Nzparametric cartesian surface: (rKrLrr) rrrHrIrerrrrrrrs r3rzParametricSurfaceSeries.__str__s|  c$++.DKK0@  OS$,, !;<  OS$,, !;<    rAc(|jddS)NrSrBrs r3rxz,ParametricSurfaceSeries.get_parameter_meshes s}}qr""rAc(|jddS)rNrSrBrs r3ryz"ParametricSurfaceSeries.get_meshess }}r""rAc Vtd}|j}t|D]i\}}|j||j |}}|j ||j |j||j|<|||<k|dd\}}} |j||j|f|_ |j||j|f|_ |j| |j| f|_ |jg|dd|ddS)aReturn arrays of coordinates for plotting. Returns ======= x : np.ndarray [n2 x n1] x-coordinates. y : np.ndarray [n2 x n1] y-coordinates. z : np.ndarray [n2 x n1] z-coordinates. mesh_u : np.ndarray [n2 x n1] Discretized u range. mesh_v : np.ndarray [n2 x n1] Discretized v range. rNrN)rr rrqrprSrTrUrVrkrlrfrgrhr~rs r3r_z ParametricSurfaceSeries.get_datas  7 #.."g& DAqwwqz2771:CBD&&C "**S"--*<=> ?GAJ  !"+1aggaj"''!*- ggaj"''!*- ggaj"''!*- $t$$@gabk@GBQK@@rAr)rErFrGrHrWrrrrrrrrr}rr~rrxryr_rrs@r3rvrvs M13 !!!!%% %% %% %% !! ##ArArvc*eZdZdZdZdZfdZxZS) ContourSeriesz"Representation for a contour plot.FTct||i||jd|jdd|_|jdd|_|jd|jdi|_y)NrrTclabels contour_kwr)rrrr show_clabelsrrqs r3rzContourSeries.__init__>sh $)&)KFD1IJ"JJy$7 #JJ| JJ~r *,rA)rErFrGrHrrrrrs@r3rr8s,LJ , ,rArc eZdZdZdZdZdZy)GenericDataSeriesaiRepresents generic numerical data. Notes ===== This class serves the purpose of back-compatibility with the "markers, annotations, fill, rectangles" keyword arguments that represent user-provided numerical data. In particular, it solves the problem of combining together two or more plot-objects with the ``extend`` or ``append`` methods: user-provided numerical data is also taken into consideration because it is stored in this series class. Also note that the current implementation is far from optimal, as each keyword argument is stored into an attribute in the ``Plot`` class, which requires a hard-coded if-statement in the ``MatplotlibBackend`` class. The implementation suggests that it is ok to add attributes and if-statements to provide more and more functionalities for user-provided numerical data (e.g. adding horizontal lines, or vertical lines, or bar plots, etc). However, in doing so one would reinvent the wheel: plotting libraries (like Matplotlib) already implements the necessary API. Instead of adding more keyword arguments and attributes, users interested in adding custom numerical data to a plot should retrieve the figure created by this plotting module. For example, this code: .. plot:: :context: close-figs :include-source: True from sympy import Symbol, plot, cos x = Symbol("x") p = plot(cos(x), markers=[{"args": [[0, 1, 2], [0, 1, -1], "*"]}]) Becomes: .. plot:: :context: close-figs :include-source: True p = plot(cos(x), backend="matplotlib") fig, ax = p._backend.fig, p._backend.ax ax.plot([0, 1, 2], [0, 1, -1], "*") fig Which is far better in terms of readability. Also, it gives access to the full plotting library capabilities, without the need to reinvent the wheel. Tc.||_||_||_yr+)r_r<r)r2rr<rs r3rzGenericDataSeries.__init__{s  "rAc|jSr+)r<rs r3r_zGenericDataSeries.get_datas yyrAN)rErFrGrHrrr_rIrAr3rrJs-\J# rArceZdZdZdZdZdZdfd ZedZ e jdZ edZ e jd Z e Z d Z d Zd Zd ZdZdZedZddZxZS)ImplicitSeriesz$Representation for 2D Implicit plot.TFr~c Tt|d i||jdd|_||_| t |n||_| t|n||_||g|_ |jd\|_ |_ |_ |jd\|_ |_|_|jd|jdd|_|j"r|jr t%d|jdd}|d kDrd }n|dkrd}d |z|_|j)y) Nr:Frr%rXr+z7Interactive plot with `adaptive=True` is not supported.rrqrI)rrrr:r>rrrrrrrrrrr_colorrr^rr;)r2r>rrrrrrs r3rzImplicitSeries.__init__s  "6" :u5  #(=c$ie +0=E$Ke&8 /3{{1~, DL$*/3{{1~, DL$*jj&**\4*HI   4==%'$% % 7A& 19E QYEY  rAcJ|jr |jS|jSr+)r:_adaptive_expr_non_adaptive_exprrs r3r>zImplicitSeries.exprs! ==&& &&&&rAc |j||jt|\}}||_||_t ||_t||_t|ttfrE|js9d|_ d}t|trd}tjd|zdzdzt|trd|_d|_y|j#||j\}}||_||_y)NTzcontains Boolean functions. zis an unequality. zThe provided expression z/In order to plot the expression, the algorithm z/automatically switched to an adaptive sampling.F)r _has_equalityrr has_equalityrrrrrmrrr:rarbr _is_equality_preprocess_meshgrid_expression)r2r>rrd is_equalitys r3r>zImplicitSeries.exprs $$T*!// >l"($i !$K d_b1 2DMM DM0C$#* MM*S0CDCD  dO ,&*D # %D !% D DT4== Y D+&*D # +D rAc|jSr+rrs r3r+zImplicitSeries.line_colors {{rAc||_yr+rr1s r3r+zImplicitSeries.line_colorrrAcd}fdgt|tr |tdDrd}||fSt|tst |d}d}||fSt|tt t frd}||fS)NFc|jD]=}t|tr |t|ts-j |?y)z8Recursively expands the arguments of an Boolean FunctionN)r<rmrrr) bool_exprrx arg_expandarg_lists r3rz0ImplicitSeries._has_equality..arg_expands= ~~ )c?3sOZ0OOC(  )rAc3RK|]}t|tttf!ywr+)rmrrrrs r3r4z/ImplicitSeries._has_equality..sV:a(K!BCVs%'Tr)rmrrrrrr)r2r>rrrs @@r3rzImplicitSeries._has_equalitys  ) dO , t VXVV# \!! D*-D!$DL\!!xh? @L\!!rAc Xd}|jdt|jt|jt||j||j ft|j t||j||jffzS)NcLt|jdk(r t|S|Sr@)rrrrs r3rz(ImplicitSeries.__str__..s#ann"5":eAhrAz5Implicit expression: %s for %s over %s and %s over %s) rrrrrrrrr)r2rrs r3rzImplicitSeries.__str__s A CE ## $  O 4<<!DJJ-0 1  O 4<<!DJJ-0 1 H   rAcb|jr|j}||S|jS)aReturns numerical data. Returns ======= If the series is evaluated with the `adaptive=True` it returns: interval_list : list List of bounding rectangular intervals to be postprocessed and eventually used with Matplotlib's ``fill`` command. dummy : str A string containing ``"fill"``. Otherwise, it returns 2D numpy arrays to be used with Matplotlib's ``contour`` or ``contourf`` commands: x_array : np.ndarray y_array : np.ndarray z_array : np.ndarray plot_type : str A string specifying which plot command to use, ``"contour"`` or ``"contourf"``. )r:ru_get_meshes_gridrs r3r_zImplicitSeries.get_datas30 ==&&(D $$&&rAc>ddlmcmcm}i}t ddd|d}t |Dcgc]}d|vs|dvs |}}|Dcgc]}t ||}}tt||}t|j|jf|j|g|} d} |j| } | Scc}wcc}w#t$r-} tj d | zd zd|_Yd} ~ | Sd} ~ wt$$r tj d d|_Y| SwxYw) aN 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 rNFT)fully_qualified_modulesinlineallow_unknown_functionsuser_functions__)rr&)rJprinterzAdaptive meshing could not be applied to the expression, as some functions are not yet implemented in the interval math module: NameError: %s z Proceeding with uniform meshing.zOAdaptive meshing could not be applied to the expression. Using uniform meshing.)(sympy.plotting.intervalmath.lib_intervalplotting intervalmath lib_intervalr(dirgetattrrrr$rrr>_get_raster_interval NameErrorrarbr:r) r2lirrrrrvalsrrTrrcs r3ruzImplicitSeries._adaptive_eval s9 >=%','+,'./ r7cat1}1Da;acc(,-1A-- T4 !TZZ0$))aSRYZ ",,T2D  /d- " MM$'**3 3 "DMM  " MM6 7"DM  "s3 B5B5B5B:"B?? D"C00(DDcvtd}|j}g}|j|jfDcgc] }t |c}\}}|j |j fDcgc] }t |c}\}} |j||d} |j|| d} |jjt| dzdz ||z zdz } |jjt| dzdz | |z zdz } | | z } | | z } t| dd| ddDcgc]\}}t||}}}t| dd| ddDcgc]\}}t||}}}|Dcgc] }|D]}||g}}}g}fd}|d k\r=t|r2||\}}|j||dz }|d k\r t|r2|jr;|D]6}|d }|d}||}|ds|d d us$|j||g8|d fScc}wcc}wcc}}wcc}}wcc}}w) z9Uses interval math to adaptively mesh and obtain the plotrN!rr%iNrc*g}g}|D]}|d}|d} ||}|ddus|ddur&|dk(r|j||g?|d|dJ|j}|j}t|j|} t||j} t|j|} t||j} |j| | g|j| | g|j| | g|j| | g||fS)ziEvaluates the intervals and subdivides the interval if the expression is partially satisfied.rr%F)TT)rmidr&rr) interval_listtemp_interval_list plot_list intervals intervalx intervaly func_evalavgxavgyr0rQrrrTs r3 refine_pixelsz:ImplicitSeries._get_raster_interval..refine_pixelsf s0"$ I* 6 &aL %aL  I6 Q<5(IaLE,A,.$$i%;<q\)Yq\-A$==D$==D $7A y}}5A $7A y}}5A&--q!f5&--q!f5&--q!f5&--q!f5/ 60&y0 0rArFr)rrrrrrrrIr r!rrr&extendrr)r2rTrUrrrsxsyexeyxsampleysamplejitterxjitteryx1x2xintery1y2yinterrsrtrrplot_list_temprrrrs ` r3rz#ImplicitSeries._get_raster_intervalC sf 7 # JJ %)\\4<<$@Aq%(AB%)ZZ$<=q%(=B++b"b)++b"b) YY^^CL )A - 1Bw    YY^^CL )A - 1Bw    7714WSb\712;1OPvr2(2r"PP14WSb\712;1OPvr2(2r"PP)/@A@A!Q@@ @  1>1f]+,9-,H )M>   ^ ,AA1f]+   * = %aL %aL  I6 Q@ffBIIbjjbmmC&89 :;   63 1 1vsJ..rAcd}t|tr|j|jz }d}||fSt|tr|j |j z }||fS|s td||fS)aIf the expression is a Relational, rewrite it as a single expression. Returns ======= expr : Expr The rewritten expression equality : Boolean Whether the original expression was an Equality or not. FTzDThe expression is not supported for plotting in uniform meshed plot.)rmrlhsrhsrgtsltsr^)r>r:equalitys r3rz.ImplicitSeries._preprocess_meshgrid_expression s dH %88dhh&DHX~j )88dhh&D X~ %3 X~rAc|dur |jS|jt|jk(r|j|j|S|jSrc)rrrrarrds r3rfzImplicitSeries.get_label sR  ;;  ;;#d112 2**4+<+rr+rXrrr_rurrrrrfrrs@r3rrs.K F B0''  [[,,: E"6  '>*XQ!f /4!rArcjtd}|j|j|dd|ddfdS)NrNrr%r)rmeanvstackrrUs r3rr s7 w B 77299eCRj%)45q 99rAc td}|j|j|ddddf|ddddf|ddddf|ddddffdS)NrNrr%r)rrdstackr s r3rwrw sy w B 77299eCRC"Ho"12ss7^"3B37^"3B38_ "#  $$rAc:td}||z jt}||z jt}|j||}|jj |}|jj |} ||| zz } t | dz|kS)z0Checks whether three points are almost collinearrNr%)rrrdotlinalgnormrw) rsrtrwrrUvector_avector_b dot_product vector_a_norm vector_b_norm cos_thetas r3r$r$ s w BA~~e$HA~~e$H&&8,KIINN8,MIINN8,M}}<=I y1}  ##rAc(ddddddd}|jD],\}}||jvs|j|||<.|ttt fvrGd|jvr3|d|d<t |ddrt|ddkDr |dd|d<|S|ttttfvrWd|jvrEt |ddr)t|ddkDr|dd|d<|dd|d<|S|dx|d<|d<|S)aAllow the use of the keyword arguments ``n, n1, n2`` to specify the number of discretization points in one and two directions, while keeping back-compatibility with older keyword arguments like, ``nb_of_points, nb_of_points_*, points``. Parameters ========== kwargs : dict Dictionary of keyword arguments passed into a plotting function. pt : type The type of the series, which indicates the kind of plot we are trying to create. rrr)rr{r|r}r~rrrr%) itemsrpoprrtrurrrzrrvr)rptreplace_old_keywordsrr2s r3rr sO  %**,&1   1 F1I& #%;  &++- !#;F4Lvc{J/S5E5I%c{1~t  M (-1 1 &++- vc{J/S5E5I%c{1~t %c{1~t  M/5Sk9t vd| MrA)rNNF)gMbP?)Rcollections.abcrsympy.calculus.utilrsympy.concreterrsympy.core.containersrsympy.core.exprrsympy.core.functionr sympy.core.sortingr sympy.core.symbolr sympy.functionsr r rrrrsympy.core.relationalrrrrrsympy.core.sympifyrsympy.externalrsympy.logic.boolalgrsympy.plotting.utilsrrsympy.printing.latexrsympy.printing.pycodersympy.printing.precedencersympy.sets.setsrr r!sympy.simplify.simplifyr"sympy.utilities.exceptionsr#sympy.utilities.lambdifyr$rr&rar(rkrur{r}rrrrrr8rtrarurnrzrvrrrrrwr$rrIrAr3rGsn$1'' %/$AA&(/D&3000-@-" B+ B *.5,%^, b b J2Bm0zm0`9#9xL,L^m/m`B)5B)L ' )5)Z:P :Pzr.0r.jzA/zA|,,,$7 7tP!ZP!n : $ $)rA