Package: chplot
Chplot - Arbitrary functions plotting and computationsChplot is a Python >= 3.9 module to plot any arbitrary mathematical expressions as well as data series from files, and compute its derivatives and integrals, where it equals zero, linear and non-linear regressions, and much more !Installationchplotis availableon Pypi, and You can install it with the command:python-mpipinstallchplotYou can also install it by cloning this repo and installing it directly:gitclonehttps://github.com/charon25/Chplot.gitcdChplot
python-mpipinstall.To check it is properly installed, just run and check it outputs the current version:python-mchplot--versionThis module requires the following third-party modules:matplotlib >= 3.6.1mpmath >= 1.2.1numpy >= 1.23.4scipy >= 1.9.3shunting_yard>= 1.0.12tqdm >= 4.64.1UsageIn the rest of this README, the term "expression" will refer to any mathematical expression, possibly with one variable (by defaultxbut can be changed).From a CLIThis module is primarly intended to be used in the command-line. To do this, use the following command:python-mchplot[expression1,[expression2,...]][additional-parameters...]Where all the additional parameters are documented in theCLI optionssection. Note that there can be no expression, as data can come from other sources.A lot of examples are given in theExamplessection.Important noteYou need to surround any expression with double quotes (") if it contains a space (). Furthermore, due to the working of theargparsePython module and the majority of shells, you may have to surround any expression with double quotes (") if it contains a caret (^). Finally, if it starts with a dash (-) you may also need to add a space () or a0before it.
For instance, you need to write" -x"or"0-x"to get the functionf(x) = -xand"x^2"(instead of justx^2) to get the square function.From Python codeThechplotmodule can also be used from another program. Code snippets:# Use this to use the built-in PlotParameters classimportchplotparameters=chplot.PlotParameters()chplot.plot(parameters)# Use this to use another object and set default valuesimportchplotparameters=...# any objectchplot.set_default_values(parameters)# add any missing field with its default valuechplot.plot(parameters)All thePlotParametersarguments are summarized in theCLI optionssection.CLI optionsNo option is mandatory.CLI optionsPlotParametersclass equivalentExpected argumentsEffect$\emptyset$expressions: list[str]Any number of expressions (including none of them) or filepathsThe expressions of the mathematical functions to plot and do computations on. If using the CLI, filepaths can also be provided, and  There can by none of them.-v--variablevariable: strOne stringThe variable going of the horizontal axis. Can be more than one character. Note that the variable will override any constant of function with the same name. Defaults tox.--no-sndisable_scientific_notation: bool$\emptyset$Disable the automatic conversion of scientific notation in every expression (e.g.1.24e-1to1.24*10^(-1)). Defaults to False.-n--n-pointsn_points: intOne positive integer (excluding zero)The number of points on the horizontal axis for the plotting of the expressions. Defaults to 10001.-i--integersis_integer: bool$\emptyset$Forces the points where the expressions are computed to be integers between the specified limits. The number of points will not exceed what is specified with the-nparameter. Defaults to False.-x--x-limx_lim: tuple[float|str|None, float|str|None]Two expressionsThe horizontal axis bounds (inclusive) where the expression are computed. First argument is the min, second is the max. Any expression (such as2pior1+exp(2)) is valid. It is also the graph default horizontal axis, but they can be automatically adjusted to accomodate the plotted data. Defaults to0 1.-xlog--xlogis_x_log: bool$\emptyset$Forces a logarithmic scale on the horizontal axis. If some horizontal axis bounds are negative, will modify them. Defaults to False.-y--y-limy_lim: tuple[float|str|None, float|str|None]Two expressionsThe vertical axis bounds (inclusive) of the graph. First argument is the min, second is the max. Any expression (such as2pior1+exp(2)) is valid. If not specified, will use matplotlib default ones to accomodate all data. Will restrict the graph to them is specified.-z--y-zeromust_contain_zero: bool$\emptyset$Forces the vertical axis to contain zero. Defaults to False.-ylog--ylogis_y_log: bool$\emptyset$Forces a logarithmic scale on the vertical axis. If some vertical axis bounds are negative, will modify them. Defaults to False.-xl--x-labelx_label: strOne stringLabel of the horizontal axis. Defaults to nothing.-yl--y-labely_label: strOne stringLabel of the vertical axis. Defaults to nothing.-t--titletitle: strOne stringTitle of the graph. Defaults to nothing.-rl--remove-legendremove_legend: bool$\emptyset$Removes the graph legend. Defaults to False.--no-plotno_plot: bool$\emptyset$Does not show the plot. However, does not prevent saving the figure. Defaults to False.-dis--discontinuousmarkersize: int|NoneOne optional positive integer (excluding zero)Transforms the style of the graph from a continuous line to discrete points with the specified radius. If present without a value, will defaults to a radius of 1. If the--integerparameter is also present, will still affect the points radius.--squaresquare_graph: bool$\emptyset$Forces the graph to be a square (aspect ratio of 1). Defaults to False.-lw--line-widthline_width: floatOne positive float (excluding zero)Width of the plotted functions. Will not affect regressions. Defaults to 1.5 (matplotlibdefaut).-c--constantsconstants: list[str]One string or more, either a filepath or of the forme<name>=<expression>Adds constants which may be used by any other expressions (including axis bounds). They must either be of the form<name>=<expression>(ega=4sin(pi/4)) or be filepath containing lines respecting this format. Note that filepaths are only accepted in the CLI. May override already existing constants and functions. If a constant refers to another one, it should be defined after. Defaults to nothing.-f--filesdata_files: list[str]One or more filepathsAdds data contained in CSV files as new functions to the graph. See theCSV files formatsection for more details. Defaults to nothing.-s--save-graphsave_figure_path: strOne filepathSaves the graph at the specified path. If not included, will not save the figure (default behavior).-d--save-datasave_data_path: strOne filepathSaves the graph data (x and y values) at the specified path in CSV format. If not included, will not save the data (default behavior).-p--python-filespython_files: list[str]One or more filepathsAdds functions contained in Python files. See theAdditional Python function formatsection for more details. Defaults to nothing.--zeroszeros_file: str|NoneOne optional filepathComputes where the expressions equal zero. If not included, will not compute it (default behavior), else if included without argument, prints the results to the console, else writes it to the given file.-int--integralintegral_file: str|NoneOne optional filepathComputes the integral of all functions on the entire interval where it is plotted. Note that it doesnotadd the antideritive of the functions to the graph, but only computes the area under them on their definition interval. If not included, will not compute it (default behavior), else if included without argument, prints the results to the console, else writes it to the given file.-deriv--derivativederivation_orders: list[int]At least one positive integer (excluding zero)Computes and adds to the graph the derivative of the specified orders of every other function. Note that the higher the order, the more inaccuracy and unstability it has. Furthermore, the derivative computation will shave off a few points on each side, so the derivatives are defined on a smaller interval.-reg--regressionregression_expression: strOne expressionComputes the coefficients of the given regression to get the best fit to every other function. The regression parameters should have the form_rXwhere X is any string made of digits, letters and underscores and starting with a letter (eg_ra0). The regressions will also be added in the final graph. When using the CLI, the expression can also be one of a few default keywords (listed inRegression default keywords).Options synergiesEvery option that computes something based on the functions will act on every function defined before it applies. The order of application is the following (each item applies to all the previous ones):Base expressions & file dataRegressionsDerivationsIntegrals & zerosFor instance, this means every regression will also be derivated, and every derivative will be integrated.CSV files formatThe--fileoption will accept any CSV file respecting those rules:the column delimiter is eitehr a comma (,), a semicolon (;), a space () or a tabulation (\t) ;the decimal separator is either a dot (.) or a comma (,) if the column delimiter is something else (for countries and language using them, such as French or German) ;text entry containing the column delimiter must be surrounded by double quotes (") ;to have double quotes (") in a text entry, just double them ("").The first column will be considered the horizontal axis data for the entire file. Each subsequent column will be a new function. They might all be of different lengths, and some value may be missing. Any missing value in the first column will ignore the whole line.The first non numerical line will be used as label for the functions.ExamplesThe filex,"First y","Second ""y""",ThirdY,EmptyColumn
0,0,,0,
1,10,100,,
2,20,,2000,
3,30,300,3000,
4,40,400,,Will result in the following functions (represented as (x,y) couples):First y: (0, 0), (1, 10), (2, 20), (3, 30), (4, 40)Second "y": (1, 100), (3, 300), (4, 400)ThirdY: (0, 0), (2, 2000), (3, 3000)Note that the last column does not have any values, so it won't be registered at all.The filex;y1;y2
0,0;1,0;2,1
0,3;1,2;2,5
0,6;1,55;2,123
1;1,825;2,99Will result in the following functions:y1: (0, 1), (0.3, 1.2), (0.6, 1.55), (1, 1.825)y2: (0, 2.1), (0.3, 2.5), (0.6, 2.123), (1, 2.99)Regression default keywordsWhen using Chplot from the command line and using the--regressioncommand, a keyword can be specified instead of an expression to get usual regression expression. Those keywords are listed below :KeywordMathematical functionEquivalent expressionconstconstant$f(x) = m$_rmlinlinear$f(x) = ax + b$_ra * x + _rbpNpolyNpolynomialNwhere $N \in \mathbb{N} $$$f(x) = \sum_{i=0}^N a_i x^i$$_ra0_ra1 * x + _ra0_ra2 * x^2 + _ra1 * x + _r0...power$f(x) = k x^\alpha$_rk * x^_ralphapowery$f(x) = k x^\alpha + y_0$_rk * x^_ralpha + r_y0log$f(x) = a \ln(x) + b$_ra * ln(x) + _rbexp$f(x) = a \mathrm{e}^{bx}$_ra * exp(x * _rb)expy$f(x) = a \mathrm{e}^{bx} + y_0$_ra * exp(x * _rb) + _ry0Note thatpoly0is equivalent toconstantandpoly1is equivalent tolinear.Additional Python function formatChplot expression can accept functions usable in any expression directly from other Python files. Those file must respect those rules:they must be in the same directory as the console when using the CLI (and in the same directory as the python execution when using the code version [NOT TESTED]) ;all functions to add must be decorated with the@plottabledecorator (importable withfrom chplot import plottable). The decoratormustindicate how many arguments is expected by the function, either directly or with thearg_countkeyword (i.e.@plottable(1)or@plottable(arg_count=2)) ;all functions must only acceptintorfloatand must only returnonevalue accepted by thefloat()built-in function of Python, such as, but not limited to,int,floatorbool(if not, will be considered as the same as a raised Exception) ;to indicate an error in the computation (such as a division by zero or the square root of a negative number), the function can either raise an exception or returnmath.nan(orfloat('nan')). Note that an exception will completely stop the computation at that point whilenanwill be used in the rest of the expression, which may change the result slightly.Everything other than those rules is allowed, such as importing other modules.
The name of the Python function will be the same as the name used in the expression.ExamplesThe Python filefunctions.pyfromchplotimportplottableimportmath@plottable(1)definc(x:float)->float:returnx+1@plottable(arg_count=2)definvradius(x:float,y:float)->float:ifx==y==0:raiseZeroDivisionErrorreturn1/math.sqrt(x*x+y*y)defdec(x:float)->float:returnx-1@plottabledefdouble(x:float)->float:returnx*2Will define2new functions usable in expression:incandinvradius.decdoes not have the decorator and will be ignored, anddoubledoes not indicate how many parameters it accepts, and therefore will also be ignored (but a warning will be logged).This means, the following command is valid:python-mchplot"inc(invradius(x, 5))"-x1inc(2)-pfunctions.pyAvailable functionsChplot is bundled by default with more than 60 mathematical and physical constants and over 200 mathematical functions from the defaultmathmodule,scipy.special,mpmathas well as custom made ones. They are all described in the following sections. The documentation of functions frommathor the third-party modules can be found in their respective wikis:math,scipy.special,mpmath.There are also the 5 base operations :+,-,*,/,^.Constantsnanand_are valid constants that both evaluates tomath.nan. They can be used to remove some points from the graph (for instance with theiforinfunctions, see below).infis also a valid constant evaluating tomath.inf.Mathematical constantschplotnameNameUsual symbolExact valuechplotvaluepiPi$\pi$$\pi$$3.141\ 592\ 653\ 589\ 793$tauTau$\tau$$2\pi$$6.283\ 185\ 307\ 179\ 586$eEuler's number$e$$$\exp(1) = \sum_{n=0}^{+\infty} \frac{1}{n!}$$$2.718\ 281\ 828\ 459\ 045$gaemEuler-Mascheroni's constant$\gamma$$$\lim_{n\to\infty} \left( \sum_{k=1}^n \left( \frac{1}{k}\right) - \log n \right)$$$0.577\ 215\ 664\ 901\ 532 9$phiGolden ratio$\phi$$\frac{1}{2} (1 + \sqrt{5})$$1.618\ 033\ 988\ 749\ 895$sqrt2Square root of 2$\sqrt{2}$$\sqrt{2}$$1.414\ 213\ 562\ 373\ 095\ 1$aperyApery's constant$$\zeta(3) = \sum_{n=1}^{+\infty} \frac{1}{n^3} $$$1.202\ 056\ 903\ 159\ 594$brunBrun's constant$B_2$Sum of the reciprocal of the twin primes$1.902\ 160\ 583\ 104$catalanCatalan's constant$G$$$\sum_{n=0}^{+\infty} \frac{(-1)^n}{(2n + 1)^2} $$$0.915\ 965\ 594\ 177\ 219$feigenbaumdFirst Feigenbaum's constant$\delta$$4.669\ 201\ 609\ 102\ 990\ 67$feigenbaumaSecond Feigenbaum's constant$\alpha$$2.502\ 907\ 875\ 095\ 892\ 82$glaisherGlaisher-Khinkelin's constant$A$$$\lim_{n\to\infty} \frac{\Pi_{k=1}^{n} k^k}{n^{\frac{n^2}{2} + \frac{n}{2} + \frac{1}{12}}\cdot\mathrm{e}^{-\frac{n^2}{4}}}$$$1.282\ 427\ 129\ 100\ 622\ 6$khinchinKhinchin's constant$K_0$$$\prod_{r=1}^{+\infty} \left(1 + \frac{1}{r(r+2)} \right)^{\log_2 r}$$$2.685\ 452\ 001\ 065\ 306\ 2$mertensMeissel-Mertens's constant$M$$$\gamma + \sum_{p\text{ prime}}\left(\ln\left(1 - \frac{1}{p}\right) + \frac{1}{p} \right)$$$0.261\ 497\ 212\ 847\ 642\ 77$Physical constantsThe constants, their values and their units are taken fromhttps://en.wikipedia.org/wiki/List_of_physical_constants.chplotnameQuantitySymbolchplotvalue (in SI units)Unitsa0Bohr's radius$a_0$$5.291\ 772\ 109\ 03\times10^{-11}$$\text{m}$alphaFine-structure constant$\alpha$$7.297\ 352\ 569\ 3\times10^{-3}$---bWien's wavelength displacement law constant$b$$2.897\ 771\ 955\times10^{-3}$$\text{m}\cdot\text{K}$bpWien's entropy displacement law constant$b_{\text{entropy}}$$3.002\ 916\ 077\times10^{-3}$$\text{m}\cdot\text{K}$bpWien's frequency displacement law constant$b'$$5.878\ 925\ 757\times10^{10}$$\text{Hz}\cdot\text{K}^{-1}$cSpeed of light in vacuum$c$$2.997\ 924\ 58\times10^8$$\text{m}\cdot\text{s}^{-1}$c1First radiation constant$c_1$$3.741\ 771\ 852\times10^{-16}$$\text{W}\cdot\text{m}^2$c1LSecond radiation constant$c_{1L}$$1.191\ 042\ 972\ 397\ 188\times10^{-16}$$\text{W}\cdot\text{m}^2\cdot\text{sr}^{-1}$c2Second radiation constant$c_2$$1.438\ 776\ 877\times10^{-2}$$\text{m}\cdot\text{K}$dnuCsHyperfine transistion frequency of Cesium-133$\Delta\nu_{\text{Cs}}$$9.192\ 631\ 770\times10^{9}$$\text{Hz}$ecElementary charge$e$$1.602\ 176\ 634\times10^{-19}$$\text{C}$EhHartree's energy$E_h$$4.359\ 744\ 722\ 207\ 1\times10^{-18}$$\text{J}$epsilon0eps0Vacuum electric permittivity$\varepsilon_0$$8.854\ 187\ 812\ 8\times10^{-12}$$\text{F}\cdot\text{m}^{-1}$eVElectronvolt value in Joule$1.602\ 176\ 634\times10^{-19}$$\text{J}$FFaraday's constant$F$$9.648\ 533\ 212\ 331\ 002\times10^4$$\text{C}\cdot\text{mol}^{-1}$GGravitational constant$G$$6.674\ 3\times10^{-11}$$\text{m}^3\cdot\text{kg}^{-1}\cdot\text{s}^{-2}$gGravity of Earth$g$$9.806\ 65$$\text{m}\cdot\text{s}^{-2}$G0Conductance quantum$G_0$$7.748\ 091\ 729\times10^{-5}$$\text{S}$geElectron g-factor$g_e$$-2.002\ 319\ 304\ 362\ 56$---GF0Fermi coupling constantReduced Fermi constant$$G^0_F$$$4.543\ 795\ 7\times10^{14}$$\text{J}^{-2}$gmuMuon g-factor$g_\mu$$-2.002\ 331\ 841\ 8$---gPProton g-factor$g_P$$5.585\ 694\ 689\ 3$---hPlanck's constant$h$$6.626\ 070\ 15\times10^{-34}$$\text{J}\cdot\text{Hz}^{-1}$hbReduced Planck's constant$\hbar$$1.054\ 571\ 817\times10^{-34}$$\text{J}\cdot\text{s}$kBBoltzmann's constant$k$, $k_B$$1.380\ 649\times10^{-23}$$\text{J}\cdot\text{K}^{-1}$keCoulomb's constant$k_e$$8.987\ 551\ 792\ 3\times10^9$$\text{N}\cdot\text{m}^2\cdot\text{C}^{-2}$KJJosephson's constant$K_J$$4.835\ 978\ 484\times10^{14}$$\text{Hz}\cdot\text{V}^{-1}$m12CAtomic mass of carbon-12$m(^{12}\text{C})$$1.992\ 646\ 879\ 92\times10^{26}$$\text{kg}$M12CMolar mass of carbon-12$M(^{12}\text{C})$$1.199\ 999\ 999\ 58\times10^{-2}$$\text{kg}\cdot\text{mol}^{-1}$meElectron mass$m_e$$9.109\ 383\ 701\ 5\times10^{-31}$$\text{kg}$mmuMuon mass$m_\mu$$1.883\ 531\ 627\times10^{-28}$$\text{kg}$mnNeutron mass$m_n$$1.674\ 927\ 498\ 04\times10^{-27}$$\text{kg}$mpProton mass$m_p$$1.672\ 621\ 923\ 69\times10^{-27}$$\text{kg}$mtTop quark mass$m_t$$3.078\ 4\times10^{-25}$$\text{kg}$mtauTau mass$m_\tau$$3.167\ 54\times10^{-27}$$\text{kg}$muAtomic mass constant$m_u$$1.660\ 539\ 066\ 6\times10^{-27}$$\text{kg}$MuMolar mass constant$M_u$$9.999\ 999\ 996\ 5\times10^{-4}$$\text{kg}\cdot\text{mol}^{-1}$mu0Vacuum magnetic parmeability$\mu_0$$1.256\ 637\ 602\ 12\times10^{-6}$$\text{N}\cdot\text{A}^{-2}$muBBohr's magneton$\mu_B$$9.274\ 010\ 078\ 3\times10^{-24}$$\text{J}\cdot\text{T}^{-1}$muNNuclear magneton$\mu_N$$5.050\ 783\ 746\ 1\times10^{-27}$$\text{J}\cdot\text{T}^{-1}$NAAvogadro constant$N_A$$6.022\ 140\ 76\times10^{23}$$\text{mol}^{-1}$RMolar gas constant$R$$8.314\ 462\ 618\ 153\ 24$$\text{J}\cdot\text{mol}^{-1}\cdot\text{K}^{-1}$reClassical electron radius$r_e$$2.817\ 940\ 326\ 2\times10^{-15}$$\text{m}$RinfRydberg's constant$R_\infty$$1.097\ 373\ 156\ 816\times10^7$$\text{m}^{-1}$RKVon Klitzing's constant$R_K$$2.581\ 280\ 745\times10^{4}$$\Omega$RyRydberg's unit of energy$R_y$$2.179\ 872\ 361\ 103\ 5\times10^{-18}$$\text{J}$sigmaStefan-Boltzmann's constant$\sigma$$5.670\ 374\ 419\times10^{-8}$$\text{W}\cdot\text{m}^{-2}\cdot\text{K}^{-4}$sigmaeThomson's cross section$\sigma_e$$6.652\ 458\ 732\ 1\times10^{-29}$$\text{m}^2$VmSiMolar volume of silicon$V_m(\text{Si})$$1.205\ 883\ 199\times10^{-5}$$\text{m}^3\cdot\text{mol}^{-1}$Z0Characteristic impedance of vacuum$Z_0$$3.767\ 303\ 136 \ 68\times10^2$$\Omega$Astronomical constantsAll the planets data are taken from :https://nssdc.gsfc.nasa.gov.chplotnameQuantitychplotvalue (in SI units)UnitsMsunSun mass$1.988\ 5\times10^{30}$$\text{kg}$MmercuryMercury mass$3.301\times10^{23}$$\text{kg}$MvenusVenus mass$4.867\ 3\times10^{24}$$\text{kg}$MearthEarth mass$5.972\ 2\times10^{24}$$\text{kg}$MmoonMoon mass$7.346\times10^{22}$$\text{kg}$MmarsMars mass$6.416\ 9\times10^{23}$$\text{kg}$MjupiterJupiter mass$1.898\ 13\times10^{27}$$\text{kg}$MsaturnSaturn mass$5.683\ 2\times10^{26}$$\text{kg}$MuranusUranus mass$8.681\ 1\times10^{25}$$\text{kg}$MneptuneNeptune mass$1.024\ 09\times10^{26}$$\text{kg}$MplutoPluto mass$1.303\times10^{22}$$\text{kg}$McharonCharon mass$1.586\times10^{21}$$\text{kg}$RsunSun volumetric mean radius$6.957\times10^{8}$$\text{m}$RmercuryMercury volumetric mean radius$2.439\ 7\times10^{6}$$\text{m}$RvenusVenus volumetric mean radius$6.051\ 8\times10^{6}$$\text{m}$RearthEarth volumetric mean radius$6.371\times10^{6}$$\text{m}$RmoonMoon volumetric mean radius$1.737\ 4\times10^{6}$$\text{m}$RmarsMars volumetric mean radius$3.389\ 5\times10^{6}$$\text{m}$RjupiterJupiter volumetric mean radius$6.991\ 1\times10^{7}$$\text{m}$RsaturnSaturn volumetric mean radius$5.8232\times10^{7}$$\text{m}$RuranusUranus volumetric mean radius$2.536\ 2\times10^{7}$$\text{m}$RneptuneNeptune volumetric mean radius$2.462\ 2\times10^{7}$$\text{m}$RplutoPluto volumetric mean radius$1.188\times10^{6}$$\text{m}$RcharonCharon volumetric mean radius$6.06\times10^{5}$$\text{m}$AUAstronomical unit in meters$1.495\ 978\ 707\times10^{11}$$\text{m}$lyLight-year in meters$9.460\ 730\ 472\ 580\ 8\times10^{15}$$\text{m}$pcParsec in meters$3.085\ 677\ 581\ 491\ 367\ 3\times10^{11}$$\text{m}$From defaultmathmoduleDocumentation:https://docs.python.org/3/library/math.htmlchplotname(s)mathnameNumber of argumentsNotesacosacos1acoshacosh1asinasin1asinhasinh1atanatan1atanhatanh1atan2atan22cbrtcbrt1ceilceil1copysigncopysign2coscos1coshcosh1degreesdegrees1distdist4dist(x1, y1, x2, y2)is interpreted asmath.dist((x1, y1), (x2, y2))erferf1erfcerfc1expexp1expm1expm11floorfloor1fmodfmod2gammagamma1hypothypot2lgammalngammalgamma1loglnlog1log10log101log1plog1p1log2log21radiansradians1remainderremainder2sinsin1sinhsinh1sqrtsqrt1tantan1trunctrunc1Fromscipy.specialDocumentation:https://docs.scipy.org/doc/scipy/reference/special.htmlchplotname(s)scipy.specialnameNumber of argumentsNotesagmagm2Aiairy1First outputAipairy1Second outputbeibei1beipbeip1berber1berpberp1betabeta2betaincbetainc3betaincinvbetaincinv3betalnbetaln2Biairy1Third outputbinombinomialbinom2Bipairy1Fourth outputChishichi1Second outputCisici1Second outputdigammadigamma1eAiairye1First outputeAipairye1Second outputeBiairye1Third outputeBipairye1Fourth outputellipeellipe1ellipeincellipeinc2ellipkellipk1ellipkincellipkinc2elliprcelliprc2elliprdelliprd3elliprfelliprf3elliprgelliprg3elliprjelliprj4erfcinverfcinv1erfierfi1erfinverfinv1factorialfacfactorial1fresnelcfresnel1Second outputfresnelsfresnel1First outputgammaincgammainc2gammainccgammaincc2gammainccinvgammainccinv2gammaincinvgammaincinv2hurwitzhurwitzzetazeta2hyp0f1hyp0f12hyp1f1hyp1f13hyp2f1hyp2f14hyperuhyperu3it2struve0it2struve01itmodstruve0itmodstruve01itstruve0itstruve01ivbesseliiv2jvbesseljjv2keikei1keipkeip1kerker1kerpkerp1kvbesselkkv2lambertwlambertw1loggammaloggamma1modstruvestruvelmodstruve2psipsi1rgammargamma1Shishichi1First outputSisici1First outputsincpisinc1struvestruvehstruve2yvbesselyyv2zetazeta1FrommpmathDocumentation:https://mpmath.org/doc/current/chplotname(s)mpmathnameNumber of argumentsNotesacotacot1acothacoth1acscacsc1acschacsch1altzetaetaaltzeta1angerjangerj2asecasec1asechasech1backlundsbacklunds1barnesgbarnesg1betainc2betainc4chebytchebyt2chebyuchebyu2clcosclcos2clsinclsin2cospicospicospi1cotcot1cothcoth1coulombccoulombc2coulombfcoulombf3coulombgcoulombg3csccsc1cschcsch1Eiei1ellipfellipf2ellippiellippi3fac2fac21ffff1fibfib1fibonaccifibonacci1gammainc2gammainc3gegenbauergegenbauer3harmonicharmonic1hermitehermite2hyp1f2hyp1f24hyp2f0hyp2f03hyp2f3hyp2f35hyp3f2hyp3f26hyperfachyperfac1jacobijacobi4laguerrelaguerre3legendrelegendre2legenplegenp3legenqlegenq3lerchphilerchphi3lili1Computesli(x, offset=False)Lili1Computesli(x, offset=True)lommels1lommels13lommels2lommels23nzetazerosnzeros1pcfdpcfd2pcfupcfu2pcfvpcfv2pcfwpcfw2polyexppolyexp2polylogpolylog2primepiprimepi1primezetaprimezeta1rfrf1riemannrriemannr1scorergiscorergi1scorerhiscorerhi1secsec1sechsech1secondzetasecondzeta1siegelthetasiegeltheta1siegelzsiegelz1sincsinc1stieltjesstieltjes1superfacsuperfac1Wlambertw1weberewebere2whitmwhitm3whitwwhitw3Probability functionschplotnameNameArgumentsExpressionnormpdfNormal distribution PDF$x, \mu, \sigma$$$\frac{1}{\sigma\sqrt{2\pi}}\mathrm{e}^{-\frac{1}{2}\left(\frac{x - \mu}{\sigma} \right)^2}$$normcdfNormal distribution CDF$x, \mu, \sigma$$$\frac{1}{2}\left(1 + \mathrm{erf}\left(\frac{x - \mu}{\sigma\sqrt{2}}\right) \right)$$unormpdfUnit normal distribution PDF$x$$$\frac{1}{\sqrt{2\pi}}\mathrm{e}^{-\frac{x^2}{2}}$$unormcdfUnit normal distribution CDF$x$$$\frac{1}{2}\left(1 + \mathrm{erf}\left(\frac{x}{\sqrt{2}}\right) \right)$$tripdfTriangle distribution PDF$x, a, b, c$$$0 \text{ if } x\leq a \text{ or } x > b$$$$\frac{2(x-a)}{(b-a)(c-a)} \text{ if } a < x\leq c$$$$\frac{2(b-x)}{(b-a)(b-c)} \text{ if } c < x\leq b$$tricdfTriangle distribution CDF$x, a, b, c$$$0 \text{ if } x < a$$$$\frac{(x-a)^2}{(b-a)(c-a)} \text{ if } a\leq x\leq c$$$$1 - \frac{(b-x)^2}{(b-a)(b-c)} \text{ if } c < x\leq b$$$$1 \text{ if }b < x $$uniformpdfUniform distribution PDF$x, a, b$$$0 \text{ if } x < a \text{ or } x > b$$$$\frac{1}{b-a} \text{ if } a\leq x\leq b$$uniformcdfUniform distribution CDF$x, a, b$$$0 \text{ if } x < a$$$$\frac{x-a}{b-a} \text{ if } a\leq x\leq b$$$$1 \text{ if }b < x $$exppdfExponential distribution PDF$x, \lambda$$$0 \text{ if } x < 0$$$$\lambda\mathrm{e}^{-\lambda x} \text{ if } 0\leq x$$expcdfExponential distribution CDF$x, \lambda$$$0 \text{ if } x < 0$$$$1 - \mathrm{e}^{-\lambda x} \text{ if } 0\leq x$$studentpdfStudent's t-distribution PDF$x, \nu$WikipediastudentcdfStudent's t-distribution CDF$x, \nu$WikipediabetapdfBeta distribution PDF$x, \alpha, \beta$WikipediabetacdfBeta distribution CDF$x, \alpha, \beta$Wikipediachi2pdfkhi2pdfChi-squared distribution PDF$x, k$Wikipediachi2cdfkhi2cdfChi-squared distribution CDF$x, k$WikipediagammapdfGamma distribution PDF$x, \alpha, \beta$WikipediagammacdfGamma distribution CDF$x, \alpha, \beta$WikipediacauchypdfCauchy distribution PDF$x, x_0, \gamma$$$\frac{1}{\pi\gamma\left(1 + \left(\frac{x - x_0}{\gamma}\right)^2\right)}$$cauchycdfCauchy distribution CDF$x, x_0, \gamma$$$\frac{1}{\pi}\arctan\left(\frac{x - x_0}{\gamma}\right) + \frac{1}{2}$$To use the ( $k, \theta$ ) parametrization of the gamma distribution, just apply $\alpha = k$ and $\beta = \frac{1}{\theta}$.Other functionsIn this table, $\{x\}$ represents the fractional part of $x$.chplotnameArgumentsExpressionreluramp$x$$0 \text{ if } x < 0$$x \text{ if } 0\leq x$lrelu$x, a$$a\cdot x \text{ if } x < 0$$x \text{ if } 0\leq x$sigmsigmoid$x$$$\frac{1}{1 + \mathrm{e}^{-x}}$$signsgn$x$$-1 \text{ if } x < 0$$0 \text{ if } x = 0$$+1 \text{ if } x > 0$lerp$x, m_x, M_x, m_y, M_y$$$m_y + (M_y - m_y)\frac{x - m_x}{M_x - m_x}$$lerpt$t, m, M$$M + t * (M - m)$heaviside$x$$0 \text{ if } x < 0$$\frac{1}{2} \text{ if } x = 0$$1 \text{ if } x > 0$rect$x$$0 \text{ if } x < -\frac{1}{2} \text{ or } x > \frac{1}{2}$$1 \text{ if } -\frac{1}{2} \leq x \leq \frac{1}{2}$triangletri$x$$0 \text{ if } x < -1 \text{ or } x > 1$$1 - |x|; \text{ if } -1 \leq x \leq 1$sawtooth$x$$2\{x - \frac{1}{2}\} - 1$squarewavesqwave$x$$\frac{1}{2} \text{ if } \{x\} = 0 \text{ or } \{x\} = \frac{1}{2}$$1 \text{ if } \{x\} < \frac{1}{2}$$0 \text{ if } \frac{1}{2} < \{x\}$trianglewavetriwave$x$$4\{x\} \text{ if } \{x\} < \frac{1}{4}$$2-4\{x\} \text{ if } \frac{1}{4} \leq \{x\} < \frac{3}{4}$$4\{x\} + 4 \text{ if } \frac{3}{4} < \{x\}$abs$x$$|x|$min$a, b$$\min(a,b)$min3$a, b, c$$\min(a,b,c)$min4$a, b, c, d$$\min(a,b,c,d)$max$a, b$$\max(a,b)$max3$a, b, c$$\max(a,b,c)$max4$a, b, c, d$$\max(a,b,c,d)$if$x, T, F$$F \text{ if } x < 0$$T \text{ if } 0\leq x$ifn$x, T, F$$T \text{ if } x\leq 0$$F \text{ if } 0 < x$ifz$x, T, F$$T \text{ if } x = 0$$F \text{ if } x\neq 0$in$x, L, U, T, F$$T \text{ if } L\leq x\leq U$$F \text{ if } x < L \text{ or } U < x$out$x, L, U, T, F$$F \text{ if } L\leq x\leq U$$T \text{ if } x < L \text{ or } U < x$Notes :out(x, L, U, T, F) = in(x, L, U, F, T)if(x, T, F) = in(x, 0, inf, T, F)ifn(x, T, F) = in(x, -inf, 0, T, F)ifn(x, T, F) = if(-x, T, F)It is possible to use_inside one of these function to remove some part of the graph.Alphabetically-sorted list of every included constants and functionsClick to reveal_a0absacosacoshacotacothacscacschagmAiAipalphaaltzetaangerjaperyasecasechasinasinhatanatan2atanhAUbbacklundsbarnesgbeibeipbentberberpbesselibesseljbesselkbesselybetabetacdfbetaincbetainc2betaincinvbetalnbetapdfBibinombinomialBipbpbruncc1c1Lc2catalancauchycdfcauchypdfcbrtceilchebytchebyuChichi2cdfchi2pdfCiclcosclsincopysigncoscoshcospicotcothcoulombccoulombfcoulombgcsccschdegreesdigammadistdnuCseeAieAipeBieBipecEhEiellipeellipeincellipfellipkellipkincellippielliprcelliprdelliprfelliprgelliprjemeps0epsilon0erferfcerfcinverfierfinvetaeVexpexpcdfexpm1exppdfFfacfac2factorialfeigenbaumafeigenbaumdfffibfibonaccifloorfmodfresnelcfresnelsGgG0gagammagammacdfgammaincgammainc2gammainccgammainccinvgammaincinvgammapdfgegegenbauerGF0glaishergmugPhharmonichbheavisidehermitehurwitzhurwitzzetahyp0f1hyp1f1hyp1f2hyp2f0hyp2f1hyp2f3hyp3f2hyperfachyperuhypotififnifzininfit2struve0itmodstruve0itstruve0ivjacobijvkBkekeikeipkerkerpkhi2cdfkhi2pdfkhinchinKJkvlaguerrelambertlambertwlegendrelegenplegenqlerchphilerplerptlgammaLililnlngammaloglog10log1plog2loggammalommels1lommels2lrelulym12CM12Cmaxmax3max4McharonmeMearthmertensminmin3min4MjupiterMmarsMmercuryMmoonmmumnMneptunemodstruvempMplutoMsaturnMsunmtmtaumuMumu0muBmuNMuranusMvenusNAnannormcdfnormpdfnzetazerosoutpcpcfdpcfupcfvpcfwphipipolyexppolylogprimepiprimezetapsiRradiansrampRcharonreRearthrectreluremainderrfrgammariemannrRinfRjupiterRKRmarsRmercuryRmoonRneptuneRplutoRsaturnRsunRuranusRvenusRysawtoothscorergiscorerhisecsechsecondzetasgnShiSisiegelthetasiegelzsigmsigmasigmaesigmoidsignsinsincsincpisinhsqrtsqrt2squarewavesqwavestieltjesstruvestruvehstruvelstudentcdfstudentpdfsuperfactantanhtautritriangletrianglewavetricdftripdftriwavetruncuniformcdfuniformpdfunormcdfunormpdfVmSiWweberewhitmwhitwyvZ0zetaGraph and computations examplesEvery file referenced in any commands can be found in theresourcesfolder.CLI parametersExpressionspython-mchplotx
python-mchplotx" -x+1""x^2"python-mchplotresources/files/equations.txt-vparameterpython-mchplott(t-1)-vt
python-mchplotsin(var*3)-vvarOverriding constant with variable:python-mchplotc
python-mchplotc-vc--no-snThe expression in the first command is interpreted as $x\times1.2\cdot10^{-1}=0.12x$, and as $1.2\mathrm{e}\cdot x - 1$ in the second.python-mchplot"x*1.2e-1"python-mchplot"x*1.2e-1"--no-sn-x,-yparametersUsing expressions in the horizontal axis bounds:python-mchplot"x^2+x"-x-33python-mchplotx-x" -sqrt(2)""zeta(3)"Using expressions in the vertical axis bounds and restricting the graph:python-mchplotfac(x)-x06python-mchplotfac(x)-x06-y0.51.5-n,-i,--disparametersThe-iparameter removes the line between points.python-mchplotcos(x)-x010-n20python-mchplotcos(x)-x010-ipython-mchplotsqrt(x)-x0100-i
python-mchplotsqrt(x)-x010--dis10-n35-xlog,-ylogparameterspython-mchplot"2^x"-x1100-ylog
python-mchplot"ln(x)"-x1100-xlogLog axis will adjust the bounds to remove negative points:python-mchplot"x^3.5"-x1100-xlog-ylog
python-mchplot"x"-x-55-xlog
python-mchplot"x"-x-5-1-xlogThe second command generates a warning:[CHPLOT] WARNING: x-axis scale is logarithmic, but its lower bound (-5.0) is negative, x-axis will be truncated to positive valuesThe third command generates en error:[CHPLOT] CRITICAL: x-axis scale is logarithmic, but both its lower (-5.0) and upper (-1.0) bounds are negative, cannot graph anything-zparameterpython-mchplot"sin(x)+10"-x110pi
python-mchplot"sin(x)+10"-x110pi-z-xl,-yl,-t,-rlparameterspython-mchplotzeta(x)-x110-y03python-mchplotzeta(x)-x110-y03-xl"Variable x"-yl"Zeta(x)"-t"Zeta function on [1 ; 10]"-rl-square,-lwparameterspython-mchplotcbrt(x)--square
python-mchplotcbrt(x)-lw5-cparameterIf a constant requires another one, define it after:python-mchplota*x+b-ca=2b=7python-mchplot"a*x^2-b*x+1"-ca=8pi/19"b=a^2-1"Constants can also be an expression, or come from a file:python-mchplotcos(a*x)-c"a=(sqrt(2) - zeta(3)) / sin(1.5)"-x050python-mchplot"a*x^3+b*x^2+c*x+d"-cresources\files\constants.txt-x-1010-fparameterAll the CSV format are summarized in theCSV files formatsection.python-mchplot-fresources\files\data.csv-dparameterpython-mchplotx"x(x+1)""x(x+1)(x+2)/2""x(x+1)(x+2)(x+3)/6"-dresources\files\saved_data.csvThe data can be found inthe saved_data.csv file.-pparameterThe filefunctions.pymust be in the directory from where the command is executed.python-mchplot"frac(x)+3""is_prime(x)""rnd(x, x/2)"-pfunctions.py-x010--zerospython-mchplotsin(x)-x-77--zeros
python-mchplot"x^2-2""in(x, 0.2, 0.3, 0, -2x+1)"-x02--zerosThe result of these commands (besides the plot) are the following. The first are the zeros of the function $\sin(x)$ on [-7 ; 7]: $\pm 2\pi$, $\pm \pi$ and $0$. Then the zero of $x^2-2$ is $\sqrt{2}$. Finally the last expression is completely zero on the interval [0.2 ; 0.3] and at $1/2$.=====ZEROSOFTHEFUNCTIONS=====Notethatnon-continuousfunctionsmaygivefalsezeros.Furthermore,somezerosmaybemissingifthegraphistangenttothex-axis.

-Ontheinterval[-7.0;7.0],thefunctionf(x)=sin(x)equalszero...atx=-6.2831853072atx=-3.1415926536atx=0.0atx=3.1415926536atx=6.2831853072=====ZEROSOFTHEFUNCTIONS=====Notethatnon-continuousfunctionsmaygivefalsezeros.Furthermore,somezerosmaybemissingifthegraphistangenttothex-axis.

-Ontheinterval[0.0;2.0],thefunctionf(x)=x^2-2equalszero...atx=1.4142135624

-Ontheinterval[0.0;2.0],thefunctionf(x)=in(x,0.2,0.3,0,-2x+1)equalszero...on[0.2;0.3]atx=0.5--integralpython-mchplot"1/x"-x1e--integral
python-mchplot"x^2""exp(x)"--integralThe result of these commands (besides the plot) are the following.$$\int_1^e\frac{dx}{x} = 1$$
$$\int_0^1x^2dx = \frac{1}{3}$$
$$\int_0^1\exp(x)dx=e - 1$$=====INTEGRALSOFTHEFUNCTIONS=====Notethatthemorepoints,thesmallesttheerrorandthatfloatingpointnumbersmayintroduceerrors.Furthermore,discontinuousfunctionsmayindicatereallyhugeerrormargins.

-∫f(x)dx=1.0000000021279944wheref(x)=1/xon[1.0;2.718]=====INTEGRALSOFTHEFUNCTIONS=====Notethatthemorepoints,thesmallesttheerrorandthatfloatingpointnumbersmayintroduceerrors.Furthermore,discontinuousfunctionsmayindicatereallyhugeerrormargins.

-∫f(x)dx=0.33333333499999834wheref(x)=x^2on[0.0;1.0]-∫f(x)dx=1.7182818298909472wheref(x)=exp(x)on[0.0;1.0]--derivparameterThe second command illustrates the instability of the higher order derivatives.python-mchplot"sin(x)"--deriv1234-x04pi
python-mchplot"exp(x)"--deriv147-n100000Synergy between--derivand--zeros/--integral.python-mchplot"x^2+2"-x-33--deriv1--zeros--integral=====ZEROSOFTHEFUNCTIONS=====Notethatnon-continuousfunctionsmaygivefalsezeros.Furthermore,somezerosmaybemissingifthegraphistangenttothex-axis.

Furthermore,onderivativesandfiledata,zerosareapproximatedusinglinearinterpolation,andmaybefarfromtheirrealvalues.
-Ontheinterval[-3.0;3.0],thefunctionf(x)=x^2+2neverequalszero.

-Ontheinterval[-2.998;2.998],thefunctionf(x)=d/dx*(x^2+2)equalszero...atx=0.0=====INTEGRALSOFTHEFUNCTIONS=====Notethatthemorepoints,thesmallesttheerrorandthatfloatingpointnumbersmayintroduceerrors.Furthermore,discontinuousfunctionsmayindicatereallyhugeerrormargins.
Thex-axislimitsonderivativesareslightlytighterbecauseofthealgorithmused.Thismaybecounteractedbyaddingmorepoints.

-∫f(x)dx=30.000000359996804wheref(x)=x^2+2on[-3.0;3.0]-∫f(x)dx=6.18809004038144e-14wheref(x)=d/dx*(x^2+2)on[-2.998;2.998]--regDefault keyword usable in the CLI.python-mchplot"sin(x)"" -exp(x)"--reglin=====REGRESSIONCOEFFICIENTSOFTHEFUNCTIONS=====Regressionfunction:reg(x)=a*x+b

-Functionf(x)=sin(x)Coefficients:a=0.85583(exact0.8558336726408089)b=0.03178(exact0.031776961574734974)Accuracyon[0.000;1.000]:R2=0.9948573993162803|err|<=0.046139649407647365|relerr|<=317.625449951033Copyableexpression:f(x)=(0.8558336726408089)*x+(0.031776961574734974)-Functionf(x)=-exp(x)Coefficients:a=-1.69032(exact-1.6903174201716293)b=-0.87314(exact-0.8731372047610497)Accuracyon[0.000;1.000]:R2=0.9837173025833181|err|<=0.15482720352636603|relerr|<=0.12686279523895028Copyableexpression:f(x)=(-1.6903174201716293)*x+(-0.8731372047610497)Arbitrary expression for regression (here: $a + \frac{b}{x} + \frac{c}{x^2}$).python-mchplot"x""x^2-3x+2"-x12--reg"_ra + _rb/x + _rc/x^2"=====REGRESSIONCOEFFICIENTSOFTHEFUNCTIONS=====Regressionfunction:reg(x)=a+b/x+c/x^2

-Functionf(x)=xCoefficients:a=4.32347(exact4.323472460240034)b=-6.08251(exact-6.082510526066791)c=2.7852(exact2.7852046542434103)Accuracyon[1.000;2.000]:R2=0.9990492201082051|err|<=0.026166588416653536|relerr|<=0.026166588416653536Copyableexpression:f(x)=(4.323472460240034)+(-6.082510526066791)/x+(2.7852046542434103)/x^2


-Functionf(x)=x^2-3x+2Coefficients:a=1.70398(exact1.7039810825081398)b=-5.44646(exact-5.446461246934391)c=3.8091(exact3.809103050454299)Accuracyon[1.000;2.000]:R2=0.8852455638434826|err|<=0.06697377834548113|relerr|<=669.2141410779176Copyableexpression:f(x)=(1.7039810825081398)+(-5.446461246934391)/x+(3.809103050454299)/x^2Regression on file data.python-mchplot-fresources\files\data.csv--regpoly2=====REGRESSIONCOEFFICIENTSOFTHEFUNCTIONS=====Regressionfunction:reg(x)=a2*x^2+a1*x+a0

-Functionf(x)=data.csv-vy(t)Coefficients:a2=0.0(exact-5.0979039530237654e-08)a1=-9.81(exact-9.809999897491432)a0=10.0(exact9.999999965897445)Accuracyon[0.000;2.030]:R2=1.0|err|<=3.608967524826312e-08|relerr|<=2.809290005481242e-06Copyableexpression:f(x)=(-5.0979039530237654e-08)*x^2+(-9.809999897491432)*x+(9.999999965897445)-Functionf(x)=data.csv-y(t)Coefficients:a2=-4.905(exact-4.904999983961847)a1=10.0(exact9.999999961872113)a0=0.0(exact1.7338066957762713e-08)Accuracyon[0.000;2.030]:R2=1.0|err|<=1.7338066957762713e-08|relerr|<=1.7041982824835924e-07Copyableexpression:f(x)=(-4.904999983961847)*x^2+(9.999999961872113)*x+(1.7338066957762713e-08)Synergy between--regand--deriv/--zeros/--integral.python-mchplotlog2(x)-x13--deriv1--reglin--zeros--integral=====REGRESSIONCOEFFICIENTSOFTHEFUNCTIONS=====Regressionfunction:reg(x)=a*x+b

-Functionf(x)=log2(x)Coefficients:a=0.76193(exact0.7619286641417374)b=-0.58912(exact-0.5891228449973627)Accuracyon[1.000;3.000]:R2=0.9808243468285833|err|<=0.17280581914437476|relerr|<=598.4874010749205Copyableexpression:f(x)=(0.7619286641417374)*x+(-0.5891228449973627)=====ZEROSOFTHEFUNCTIONS=====Notethatnon-continuousfunctionsmaygivefalsezeros.Furthermore,somezerosmaybemissingifthegraphistangenttothex-axis.

Furthermore,onderivativesandfiledata,zerosareapproximatedusinglinearinterpolation,andmaybefarfromtheirrealvalues.
-Ontheinterval[1.0;3.0],thefunctionf(x)=log2(x)equalszero...atx=1.0

-Ontheinterval[1.0;3.0],thefunctionf(x)=Regression[log2(x)]neverequalszero.

-Ontheinterval[1.001;2.999],thefunctionf(x)=d/dx*(log2(x))neverequalszero.

-Ontheinterval[1.001;2.999],thefunctionf(x)=d/dx*(Regression[log2(x)])neverequalszero.=====INTEGRALSOFTHEFUNCTIONS=====Notethatthemorepoints,thesmallesttheerrorandthatfloatingpointnumbersmayintroduceerrors.Furthermore,discontinuousfunctionsmayindicatereallyhugeerrormargins.
Thex-axislimitsonderivativesareslightlytighterbecauseofthealgorithmused.Thismaybecounteractedbyaddingmorepoints.

-∫f(x)dx=1.8694974171793488wheref(x)=log2(x)on[1.0;3.0]-∫f(x)dx=1.8694689665720188wheref(x)=Regression[log2(x)]on[1.0;3.0]-∫f(x)dx=1.583424040388957wheref(x)=d/dx*(log2(x))on[1.001;2.999]-∫f(x)dx=1.5226382424208345wheref(x)=d/dx*(Regression[log2(x)])on[1.001;2.999]Possible improvementsParallelizing computation of expressions.