K i(4ddlmZ ddlmZddlmZddlm Z ddl m Z ddl m Z ddlmZdd lmZdd lmZdd lmZdd lmZdd lmZddlmZddlmZmZddlZedGddZ GddZ!y#e$r edwxYw))RLockNz;pyglet is required for plotting. visit https://pyglet.org/)Integer) SYMPY_INTS)GeometryEntity)PlotAxes)PlotMode) PlotObject) PlotWindow)parse_option_string)doctest_depends_on) is_sequence)sleepgetcwdlistdirpygletmodulesceZdZdZeddZdZdZddZd Z d Z d Z d Z d Z dZdZdZdZdZdZdZy) PygletPlotag Plot Examples ============= See examples/advanced/pyglet_plotting.py for many more examples. >>> from sympy.plotting.pygletplot import PygletPlot as Plot >>> from sympy.abc import x, y, z >>> Plot(x*y**3-y*x**3) [0]: -x**3*y + x*y**3, 'mode=cartesian' >>> p = Plot() >>> p[1] = x*y >>> p[1].color = z, (0.4,0.4,0.9), (0.9,0.4,0.4) >>> p = Plot() >>> p[1] = x**2+y**2 >>> p[2] = -x**2-y**2 Variable Intervals ================== The basic format is [var, min, max, steps], but the syntax is flexible and arguments left out are taken from the defaults for the current coordinate mode: >>> Plot(x**2) # implies [x,-5,5,100] [0]: x**2, 'mode=cartesian' >>> Plot(x**2, [], []) # [x,-1,1,40], [y,-1,1,40] [0]: x**2, 'mode=cartesian' >>> Plot(x**2-y**2, [100], [100]) # [x,-1,1,100], [y,-1,1,100] [0]: x**2 - y**2, 'mode=cartesian' >>> Plot(x**2, [x,-13,13,100]) [0]: x**2, 'mode=cartesian' >>> Plot(x**2, [-13,13]) # [x,-13,13,100] [0]: x**2, 'mode=cartesian' >>> Plot(x**2, [x,-13,13]) # [x,-13,13,10] [0]: x**2, 'mode=cartesian' >>> Plot(1*x, [], [x], mode='cylindrical') ... # [unbound_theta,0,2*Pi,40], [x,-1,1,20] [0]: x, 'mode=cartesian' Coordinate Modes ================ Plot supports several curvilinear coordinate modes, and they independent for each plotted function. You can specify a coordinate mode explicitly with the 'mode' named argument, but it can be automatically determined for Cartesian or parametric plots, and therefore must only be specified for polar, cylindrical, and spherical modes. Specifically, Plot(function arguments) and Plot[n] = (function arguments) will interpret your arguments as a Cartesian plot if you provide one function and a parametric plot if you provide two or three functions. Similarly, the arguments will be interpreted as a curve if one variable is used, and a surface if two are used. Supported mode names by number of variables: 1: parametric, cartesian, polar 2: parametric, cartesian, cylindrical = polar, spherical >>> Plot(1, mode='spherical') Calculator-like Interface ========================= >>> p = Plot(visible=False) >>> f = x**2 >>> p[1] = f >>> p[2] = f.diff(x) >>> p[3] = f.diff(x).diff(x) >>> p [1]: x**2, 'mode=cartesian' [2]: 2*x, 'mode=cartesian' [3]: 2, 'mode=cartesian' >>> p.show() >>> p.clear() >>> p >>> p[1] = x**2+y**2 >>> p[1].style = 'solid' >>> p[2] = -x**2-y**2 >>> p[2].style = 'wireframe' >>> p[1].color = z, (0.4,0.4,0.9), (0.9,0.4,0.4) >>> p[1].style = 'both' >>> p[2].style = 'both' >>> p.close() Plot Window Keyboard Controls ============================= Screen Rotation: X,Y axis Arrow Keys, A,S,D,W, Numpad 4,6,8,2 Z axis Q,E, Numpad 7,9 Model Rotation: Z axis Z,C, Numpad 1,3 Zoom: R,F, PgUp,PgDn, Numpad +,- Reset Camera: X, Numpad 5 Camera Presets: XY F1 XZ F2 YZ F3 Perspective F4 Sensitivity Modifier: SHIFT Axes Toggle: Visible F5 Colors F6 Close Window: ESCAPE ============================= rrcvddlm}||_d|_t |_i|_g|_t||_ t|jdd}td i||_ |jj|j||d<|jddr|j!yy) a Positional Arguments ==================== Any given positional arguments are used to initialize a plot function at index 1. In other words... >>> from sympy.plotting.pygletplot import PygletPlot as Plot >>> from sympy.abc import x >>> p = Plot(x**2, visible=False) ...is equivalent to... >>> p = Plot(visible=False) >>> p[1] = x**2 Note that in earlier versions of the plotting module, you were able to specify multiple functions in the initializer. This functionality has been dropped in favor of better automatic plot plot_mode detection. Named Arguments =============== axes An option string of the form "key1=value1; key2 = value2" which can use the following options: style = ordinate none OR frame OR box OR ordinate stride = 0.25 val OR (val_x, val_y, val_z) overlay = True (draw on top of plot) True OR False colored = False (False uses Black, True uses colors R,G,B = X,Y,Z) True OR False label_axes = False (display axis names at endpoints) True OR False visible = True (show immediately True OR False The following named arguments are passed as arguments to window initialization: antialiasing = True True OR False ortho = False True OR False invert_mouse_zoom = False True OR False ) plot_modesNaxesrvisibleT)rr _win_args_windowr _render_lock _functions _pobjects ScreenShot _screenshotr poprrappendgetshow)selffargswin_argsr axe_optionss d/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sympy/plotting/pygletplot/plot.py__init__zPygletPlot.__init__sL !! !G%d+)(,,vr*BC +{+  dii(Q << 4 ( IIK )c|jr1|jjs|jjyd|jd<|jj t |fi|j|_y)z~ Creates and displays a plot window, or activates it (gives it focus) if it has already been created. TrN)r has_exitactivaterrreset_resourcesr r*s r.r)zPygletPlot.shows\ << 5 5 LL ! ! #(,DNN9 % II % % ' &d=dnn=DLr0cR|jr|jjyy)z) Closes the plot window. N)r closer5s r.r7zPygletPlot.closes  << LL    r0Nc>|jj|||y)aK Saves a screen capture of the plot window to an image file. If outfile is given, it can either be a path or a file object. Otherwise a png image will be saved to the current working directory. If the format is omitted, it is determined from the filename extension. N)r%saver*outfileformatsizes r. saveimagezPygletPlot.saveimages gvt4r0c|jji|_|j|jj y)z8 Clears the function list of this plot. Nr!acquirer"adjust_all_boundsreleaser5s r.clearzPygletPlot.clears; !!#   !!#r0c |j|S)zR Returns the function at position i in the function list. )r"r*is r. __getitem__zPygletPlot.__getitem__&s q!!r0ct|ttfr|dk\s tdt|tr|}nFt |rt|t r|g}t|dk(ryd|ji}t|i|}|rD|jj||j|<|jjytddjd|Dz)zJ Parses and adds a PlotMode to the function list. rz'Function index must be an integer >= 0.Nbounds_callbackzFailed to parse '%s'.z, c32K|]}t|ywNstr).0as r. z)PygletPlot.__setitem__..Fs51A5s) isinstancerr ValueErrorr r rlenrBrr!rAr"rCjoin)r*rGargsfkwargss r. __setitem__zPygletPlot.__setitem__-s 1z734a34 4 dJ 'A%*T>*Jv4yA~')?)?@F$)&)A    % % '!"DOOA     % % '4ii55567 7r0c|jj|j|=|j|jj y)zR Removes the function in the function list at position i. Nr@rFs r. __delitem__zPygletPlot.__delitem__Hs@ !!# OOA    !!#r0cd}|jj||jvr|dz }||jvr|jj|S)zF Returns the first unused index in the function list. rr)r!rAr"rCrFs r.firstavailableindexzPygletPlot.firstavailableindexRsU  !!#4??" FA4??" !!#r0cD|j|j|y)zg Parses and adds a PlotMode to the function list at the first available index. N)rYr])r*rVs r.r'zPygletPlot.append]s 113T:r0c,t|jS)zG Returns the number of functions in the function list. )rTr"r5s r.__len__zPygletPlot.__len__ds4??##r0c6|jjS)z8 Allows iteration of the function list. )r" itervaluesr5s r.__iter__zPygletPlot.__iter__js))++r0ct|SrLrMr5s r.__repr__zPygletPlot.__repr__ps 4yr0c Jd}t|jdk(r|dz }|S|jj|dj |jDcgc] }dd|t |j|fz"c}z }|jj |Scc}w)zv Returns a string containing a new-line separated list of the functions in the function list. rrz  z %s[%i]: %s)rTr"r!rArUrNrC)r*srGs r.__str__zPygletPlot.__str__ss  t 1 $  A     % % ' %)__6 !)B3tq7I3J+KK67 7A    % % '6s%B c&|jj|jj|jD]4}|jj |j|j 6|jjyrL)r!rArreset_bounding_boxr" adjust_boundsboundsrC)r*rWs r.rBzPygletPlot.adjust_all_boundssj !!# $$& ?A II # #DOOA$6$=$= > ? !!#r0c\td|jj|jD]^}|j|j}|j|j }|s|sDtd|r|r`|jj y)Nr)rr!rAr"_get_calculating_verts_get_calculating_cvertsrC)r*rWrPbs r.wait_for_calculationsz PygletPlot.wait_for_calculationss a !!# A"99A"::A#a#  !!#r0Nr)iXi)__name__ __module__ __qualname____doc__r r/r)r7r>rDrHrYr[r]r'r`rcrerirBrrrr0r.rrsp~@ ,V-Vt> ! 5$"76$ ;$ ,  $$r0rc,eZdZdZdZdZddZdZy)r$cX||_d|_d|_d|_d|_d|_y)NFrr)_plotscreenshot_requestedr;r< invisibleModeflag)r*plots r.r/zScreenShot.__init__s. $)!  " r0c|jSrL)r{r5s r.__bool__zScreenShot.__bool__s(((r0c |jdkr|xjdz c_y|jjj\}}||zdzt j tj z}t j|}tjdd||tjtj|ddl m }|jd||f|jdddd}|j!|j"j%|j&|j(d|_d|_|j,r%|jjj/yy) Nrr)ImageRGBArawF)r}rzr get_sizectypessizeofc_ubytecreate_string_bufferpgl glReadPixelsGL_RGBAGL_UNSIGNED_BYTEPILr frombufferr transposeFLIP_TOP_BOTTOMr9r;r<r{r|r7)r*size_xsize_yr=imagerims r._execute_savingzScreenShot._execute_savings 99q= IINI ++446f}Qv}}V^^<<++D1 Avvs{{C U**+00t{{K $)!    JJ   $ $ & r0Nc||_||_||_d|_|jj r |jj j rd|jjd<|d|jjd<|d|jjd<|jjjt|jfi|jj|j_d|_ |j+|j|_t|jyy)NTFrrwidthrheight)r;r<r=r{rzr r2rrr4r r|_create_unique_pathprintr:s r.r9zScreenShot.saves   $(!zz!!TZZ%7%7%@%@.3DJJ  +,0GDJJ  )-1!WDJJ  * JJOO + + -!+DJJ!O$**:N:N!ODJJ !%D  << 335DL $,,  r0cft}t|}d}d} d|z|vr |d|zz} |S|dz })Nrrz plot_%s.pngz /plot_%s.pngrr)r*cwdlpathrGs r.rzScreenShot._create_unique_pathsSh CL  1$)^a//  FA r0rs)rtrurvr/rrr9rrr0r.r$r$s)'& ( r0r$)" threadingr pyglet.glglr ImportErrorsympy.core.numbersrsympy.external.gmpyrsympy.geometry.entityr#sympy.plotting.pygletplot.plot_axesr#sympy.plotting.pygletplot.plot_moder%sympy.plotting.pygletplot.plot_objectr %sympy.plotting.pygletplot.plot_windowr sympy.plotting.pygletplot.utilr sympy.utilities.decoratorr sympy.utilities.iterablesr timerosrrrrr$rr0r.rs3 '*088<<>81 K(v$v$)v$p ==[ 3 2 333s A==B