{f)dZddlmZmZddlmZddlmZGddeZ dd gd d d d gd fd Z d Z gdZ dZ dd gdd gdd dd d d fdZdd gdd gdddd d d fdZe e _ e e _ e e _ ee _ee _y )z Plotting (requires matplotlib) ) hsv_to_rgb hls_to_rgb) NoConvergence)xrangeceZdZeeeefZy)VisualizationMethodsN)__name__ __module__ __qualname__ ValueErrorArithmeticErrorZeroDivisionErrorr plot_ignore]/var/lib/jenkins/workspace/mettalog/venv/lib/python3.12/site-packages/mpmath/visualization.pyr r s0A=QKrr Nc |rd}d} |s%ddl} | j} | jd}t|tt fs|g}|\} } gd} t |D]#\}}|j| | | | z t|z }g}g}d}tt|D]"} |dk7r!|D]}||dz |ks|||k\st|||}|j|st|dkDrtt|drn|jrbt|j }t|j}|sd }|j#|g}|j#t||||fnN|rd}|j#|g}t|d r |j }|j#t|||f%|r|j#||D]}|Dcgc]}|d }}|Dcgc]}|d }}|s*| |t| z}t|dd k(rC|Dcgc]}|d  }}|j'||d |zd |j'||d|zd |j'|||d &|j)|Dcgc] }t|c}|r(|j+|Dcgc] }t|c}|j-d|j/d|j1d | r'|r j3||y j5yy#|j$$r|r|j#|g}YwxYwcc}wcc}wcc}wcc}wcc}w)a Shows a simple 2D plot of a function `f(x)` or list of functions `[f_0(x), f_1(x), \ldots, f_n(x)]` over a given interval specified by *xlim*. Some examples:: plot(lambda x: exp(x)*li(x), [1, 4]) plot([cos, sin], [-4, 4]) plot([fresnels, fresnelc], [-4, 4]) plot([sqrt, cbrt], [-4, 4]) plot(lambda t: zeta(0.5+t*j), [-20, 20]) plot([floor, ceil, abs, sign], [-5, 5]) Points where the function raises a numerical exception or returns an infinite value are removed from the graph. Singularities can also be excluded explicitly as follows (useful for removing erroneous vertical lines):: plot(cot, ylim=[-5, 5]) # bad plot(cot, ylim=[-5, 5], singularities=[-pi, 0, pi]) # good For parts where the function assumes complex values, the real part is plotted with dashes and the imaginary part is plotted with dots. .. note :: This function requires matplotlib (pylab). Nro)brgmkFrgu<7~imagTrealz--) linewidth:xzf(x)dpi)pylabfigure add_subplot isinstancetuplelist enumeratearangefloatrlenr isnanabshasattrrrappendrplotset_xlimset_ylim set_xlabel set_ylabelgridsavefigshow)ctxfxlimylimpointsfiler& singularitiesaxesfigr'arcolorsnfuncr$segmentssegment in_complexisingvreimsycz_s rr5r5 s58  C llns# a% ' C DAq &FQ<4 JJq!ac5=0 1 AA 6 -QqS6T>addl",,!.1J99Q<3q6E>$$1f%!&&qvvBqvvB%%)  0"$NNE!A$KR#89!%*  0"$q&)FFNNE!A$K#341 :  OOG $G&'!1'A'&'!1'A'q3v;'A71:!##*+aQqT++ !QQ! 4 !QA 3 !QQ / I ` MMT*58*+  .AuQx./OOCOOFIIdO  MM$CM ( JJL  1?? OOG, (' , +.s=#L19L1C?L1 M2 M!) M&M+;M01$MMc&|j|ry|j|ryd}t|j||jzd|jzz }|dzdz}dtddt |dzzz z }t ||d S) N?rYrY?r[r[(-DT! @r!r[rYr333333?皙?)isinfr1r/argpir2r)r=rUrarFrs rdefault_color_functionrbos yy| yy| B swwqz SVV ##&&1A SCA eAs3q63;'((A aC  r) )rere)gffffff)皙?g?r[)g)rer[rY)g)g?r^r^)rerX)g?)rY?r])r[)rgr[re)gffffff?)gffffff?rfre)rYrd)@rdc|j|ry|j|ryd}t|j||z }t t |dd}t dttD]a}t|d|kDst|dz \}\}}}t|\} \} } } ||z | |z z } || |z | zz|| |z | zz|| |z | zzfcSy)NrXrZr\rYrcrr) r_r1r/r`maxminranger0blue_orange_colors)r=rUrawrMrFragabarrbgbbbrRs rphase_color_functionrus yy| yy| B cggajBA C3KA 1S+, - a  #a '015OA|B03OA|B11 Ar"uai<RUAIr2b5!)|; ; .riFc ||dk(r |j}|dk(r |j}ddl} |rd} d} | s!| j} | j d} |\} } |\}}| | z }||z }t |j ||z|z dz}t |j ||z|z dz}| j| | |}| j|||}| j||df}t|D]f}t|D]0}|j||||} |||}||||f<2|sDtt|d zt|zh| | ||fDcgc] }t|c}\} } }}| j|| | ||fd | j!d | j#d | r'|r| j%||y| j'yy#|j$rd}YwxYwcc}w)a Plots the given complex-valued function *f* over a rectangular part of the complex plane specified by the pairs of intervals *re* and *im*. For example:: cplot(lambda z: z, [-2, 2], [-10, 10]) cplot(exp) cplot(zeta, [0, 1], [0, 50]) By default, the complex argument (phase) is shown as color (hue) and the magnitude is show as brightness. You can also supply a custom color function (*color*). This function should take a complex number as input and return an RGB 3-tuple containing floats in the range 0.0-1.0. Alternatively, you can select a builtin color function by passing a string as *color*: * "default" - default color scheme * "phase" - a color scheme that only renders the phase of the function, with white for positive reals, black for negative reals, gold in the upper half plane, and blue in the lower half plane. To obtain a sharp image, the number of points may need to be increased to 100,000 or thereabout. Since evaluating the function that many times is likely to be slow, the 'verbose' option is useful to display progress. .. note :: This function requires matplotlib (pylab). Ndefaultphaserrrr rZz of lower)extentoriginzRe(z)zIm(z)r%)rbrur'r(r)intsqrtlinspacezerosrmpcrprintstrr/imshowr8r9r;r<)r=r>rPrQrAcolorverboserBr&rDr'rErearebimaimbdredimMNr$rSrnrHrrUrOrVs rcplotrs @ }*** ((  C llns#HCHC )C )C CHHVCZ^ $Q &'A CHHVCZ^ $Q &'A sC#A sC#A  Q1IA AYA!ad#A $!A$KAacF   #a&6/CF* +.1#sC,@Aq%(ACc3KK3S#.wK?OOGOOG  MM$CM ( JJL  ?? $# $ BsG "G7 G43G4dTc ddl} ddlm} |rd} d} | s+| j} | jj | } |\} }|\}}|| z }||z }t |ttfs||g}|\}}| j| ||}| j|||}tdDcgc]}| j||fc}\}}}tdDcgc]}ddgc}\}}}t|D]}t|D]}||j|||j||} |\|||f<|||f<|||f<|||f|f|||f|f|||f|ffD] \}} || dkr|| d<|| dkDs|| d<"|r| j|||ddn| j|||dd| j!d| j#d| j%d |r|||fD cgc] } | d| dz c} \}!}"}#t'|!|"|#}$|!|$kr)|$|!z }%| j)|d|%d z z |d|%d z z|"|$kr)|$|"z }%| j+|d|%d z z |d|%d z z|#|$kr)|$|#z }%| j-|d|%d z z |d|%d z z| r'|r| j/|| y| j1yycc}wcc}w#t$r |||||c|||f<|||f<|||f<YwxYwcc} w) a Plots the surface defined by `f`. If `f` returns a single component, then this plots the surface defined by `z = f(x,y)` over the rectangular domain with `x = u` and `y = v`. If `f` returns three components, then this plots the parametric surface `x, y, z = f(u,v)` over the pairs of intervals `u` and `v`. For example, to plot a simple function:: >>> from mpmath import * >>> f = lambda x, y: sin(x+y)*cos(y) >>> splot(f, [-pi,pi], [-pi,pi]) # doctest: +SKIP Plotting a donut:: >>> r, R = 1, 2.5 >>> f = lambda u, v: [r*cos(u), (R+r*sin(u))*cos(v), (R+r*sin(u))*sin(v)] >>> splot(f, [0, 2*pi], [0, 2*pi]) # doctest: +SKIP .. note :: This function requires matplotlib (pylab) 0.98.5.3 or higher. rNr r)rstridecstrider$rSrUrhr%)r'mpl_toolkits.mplot3dmplot3dr(axes3dAxes3Dr*r,r+r~rrconvert TypeErrorplot_wireframe plot_surfacer8r9 set_zlabelrj set_xlim3d set_ylim3d set_zlim3dr;r<)&r=r>urOrA keep_aspect wireframerBr&rDr'rrEuaubvavbdudvrrrMr$rSrUxabyabzabrHrfdatarTcabdxdydzmaxddeltas& rsplotrsd4*  C lln~~$$S) FB FB bB bB ftUm ,&! DAq r2q!A r2q!A,21I6qu{{Aq6"6GAq!%+AY/aV/MCc AYAckk!A$'QqT):;E ;).&!A#!A#!A#acFC=1QqS63-!AaC&#G3s1v:CFs1v:CF H  Aq!Q: !Q1a8OOCOOCOOC25sCA#c!fs1voA B2r2 92IE OOCFUS[0#a&53;2F G 92IE OOCFUS[0#a&53;2F G 92IE OOCFUS[0#a&53;2F G  MM$CM ( JJL  C7/  ;)*1qtU&!A#!A#!A# ;Bs$$K  K.K/K?%K<;K<)__doc__colorsysrrlibmpr libmp.backendrobjectr r5rbrmrurrrrrrs, !R6R!f4$D4aF !  <VAt4 $TJXFr!fSd$TPf!.D+,@)""r