Chplot 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 !
chplot
is available on Pypi, and You can install it with the command:
python -m pip install chplot
You can also install it by cloning this repo and installing it directly:
git clone https://github.com/charon25/Chplot.git
cd Chplot
python -m pip install .
To check it is properly installed, just run and check it outputs the current version:
python -m chplot --version
This module requires the following third-party modules:
- matplotlib >= 3.6.1
- mpmath >= 1.2.1
- numpy >= 1.23.4
- scipy >= 1.9.3
- shunting_yard >= 1.0.12
- tqdm >= 4.64.1
In the rest of this README, the term "expression" will refer to any mathematical expression, possibly with one variable (by default x
but can be changed).
This module is primarly intended to be used in the command-line. To do this, use the following command:
python -m chplot [expression1, [expression2, ...]] [additional-parameters...]
Where all the additional parameters are documented in the CLI options section. Note that there can be no expression, as data can come from other sources.
A lot of examples are given in the Examples section.
You need to surround any expression with double quotes ("
) if it contains a space (
). Furthermore, due to the working of the argparse
Python 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 a 0
before it.
For instance, you need to write " -x"
or "0-x"
to get the function f(x) = -x
and "x^2"
(instead of just x^2
) to get the square function.
The chplot
module can also be used from another program. Code snippets:
# Use this to use the built-in PlotParameters class
import chplot
parameters = chplot.PlotParameters()
chplot.plot(parameters)
# Use this to use another object and set default values
import chplot
parameters = ... # any object
chplot.set_default_values(parameters) # add any missing field with its default value
chplot.plot(parameters)
All the PlotParameters
arguments are summarized in the CLI options section.
No option is mandatory.
CLI options |
PlotParameters class equivalent |
Expected arguments | Effect |
---|---|---|---|
expressions: list[str] | Any number of expressions (including none of them) or filepaths | The 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 --variable
|
variable: str | One string | The 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 to x . |
--no-sn |
disable_scientific_notation: bool | Disable the automatic conversion of scientific notation in every expression (e.g. 1.24e-1 to 1.24*10^(-1) ). Defaults to False. |
|
-n --n-points
|
n_points: int | One positive integer (excluding zero) | The number of points on the horizontal axis for the plotting of the expressions. Defaults to 10001. |
-i --integers
|
is_integer: bool | 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 -n parameter. Defaults to False. |
|
-x --x-lim
|
x_lim: tuple[float|str|None, float|str|None] | Two expressions | The horizontal axis bounds (inclusive) where the expression are computed. First argument is the min, second is the max. Any expression (such as 2pi or 1+exp(2) ) is valid. It is also the graph default horizontal axis, but they can be automatically adjusted to accomodate the plotted data. Defaults to 0 1 . |
-xlog --xlog
|
is_x_log: bool | Forces a logarithmic scale on the horizontal axis. If some horizontal axis bounds are negative, will modify them. Defaults to False. | |
-y --y-lim
|
y_lim: tuple[float|str|None, float|str|None] | Two expressions | The vertical axis bounds (inclusive) of the graph. First argument is the min, second is the max. Any expression (such as 2pi or 1+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-zero
|
must_contain_zero: bool | Forces the vertical axis to contain zero. Defaults to False. | |
-ylog --ylog
|
is_y_log: bool | Forces a logarithmic scale on the vertical axis. If some vertical axis bounds are negative, will modify them. Defaults to False. | |
-xl --x-label
|
x_label: str | One string | Label of the horizontal axis. Defaults to nothing. |
-yl --y-label
|
y_label: str | One string | Label of the vertical axis. Defaults to nothing. |
-t --title
|
title: str | One string | Title of the graph. Defaults to nothing. |
-rl --remove-legend
|
remove_legend: bool | Removes the graph legend. Defaults to False. | |
--no-plot |
no_plot: bool | Does not show the plot. However, does not prevent saving the figure. Defaults to False. | |
-dis --discontinuous
|
markersize: int|None | One 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 --integer parameter is also present, will still affect the points radius. |
--square |
square_graph: bool | Forces the graph to be a square (aspect ratio of 1). Defaults to False. | |
-lw --line-width
|
line_width: float | One positive float (excluding zero) | Width of the plotted functions. Will not affect regressions. Defaults to 1.5 (matplotlib defaut). |
-c --constants
|
constants: 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> (eg a=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 --files
|
data_files: list[str] | One or more filepaths | Adds data contained in CSV files as new functions to the graph. See the CSV files format section for more details. Defaults to nothing. |
-s --save-graph
|
save_figure_path: str | One filepath | Saves the graph at the specified path. If not included, will not save the figure (default behavior). |
-d --save-data
|
save_data_path: str | One filepath | Saves 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-files
|
python_files: list[str] | One or more filepaths | Adds functions contained in Python files. See the Additional Python function format section for more details. Defaults to nothing. |
--zeros |
zeros_file: str|None | One optional filepath | Computes 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 --integral
|
integral_file: str|None | One optional filepath | Computes the integral of all functions on the entire interval where it is plotted. Note that it does not add 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 --derivative
|
derivation_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 --regression
|
regression_expression: str | One expression | Computes the coefficients of the given regression to get the best fit to every other function. The regression parameters should have the form _rX where 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 in Regression default keywords). |
Every 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 data
- Regressions
- Derivations
- Integrals & zeros
For instance, this means every regression will also be derivated, and every derivative will be integrated.
The --file
option will accept any CSV file respecting those rules:
- the column delimiter is eitehr a comma (
,
), a semicolon (;
), a space (\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.
The file
x,"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 file
x;y1;y2
0,0;1,0;2,1
0,3;1,2;2,5
0,6;1,55;2,123
1;1,825;2,99
Will 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)
When using Chplot from the command line and using the --regression
command, a keyword can be specified instead of an expression to get usual regression expression. Those keywords are listed below :
Keyword | Mathematical function |
Equivalent expression |
---|---|---|
const constant
|
_rm |
|
lin linear
|
_ra * x + _rb |
|
pN polyN polynomialN where |
_ra0 _ra1 * x + _ra0 _ra2 * x^2 + _ra1 * x + _r0 ...
|
|
power |
_rk * x^_ralpha |
|
powery |
_rk * x^_ralpha + r_y0 |
|
log |
_ra * ln(x) + _rb |
|
exp |
_ra * exp(x * _rb) |
|
expy |
_ra * exp(x * _rb) + _ry0 |
Note that poly0
is equivalent to constant
and poly1
is equivalent to linear
.
Chplot 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
@plottable
decorator (importable withfrom chplot import plottable
). The decorator must indicate how many arguments is expected by the function, either directly or with thearg_count
keyword (i.e.@plottable(1)
or@plottable(arg_count=2)
) ; - all functions must only accept
int
orfloat
and must only return one value accepted by thefloat()
built-in function of Python, such as, but not limited to,int
,float
orbool
(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 return
math.nan
(orfloat('nan')
). Note that an exception will completely stop the computation at that point whilenan
will 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.
The Python file functions.py
from chplot import plottable
import math
@plottable(1)
def inc(x: float) -> float:
return x + 1
@plottable(arg_count=2)
def invradius(x: float, y: float) -> float:
if x == y == 0:
raise ZeroDivisionError
return 1 / math.sqrt(x * x + y * y)
def dec(x: float) -> float:
return x - 1
@plottable
def double(x: float) -> float:
return x * 2
Will define 2 new functions usable in expression: inc
and invradius
. dec
does not have the decorator and will be ignored, and double
does 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 -m chplot "inc(invradius(x, 5))" -x 1 inc(2) -p functions.py
Chplot is bundled by default with more than 60 mathematical and physical constants and over 200 mathematical functions from the default math
module, scipy.special
, mpmath
as well as custom made ones. They are all described in the following sections. The documentation of functions from math
or the third-party modules can be found in their respective wikis: math, scipy.special, mpmath.
There are also the 5 base operations : +
, -
, *
, /
, ^
.
nan
and _
are valid constants that both evaluates to math.nan
. They can be used to remove some points from the graph (for instance with the if
or in
functions, see below). inf
is also a valid constant evaluating to math.inf
.
chplot name |
Name | Usual symbol | Exact value |
chplot value |
---|---|---|---|---|
pi |
Pi | |||
tau |
Tau | |||
e |
Euler's number | |||
ga em
|
Euler-Mascheroni's constant | |||
phi |
Golden ratio | |||
sqrt2 |
Square root of 2 | |||
apery |
Apery's constant | |||
brun |
Brun's constant | Sum of the reciprocal of the twin primes | ||
catalan |
Catalan's constant | |||
feigenbaumd |
First Feigenbaum's constant | |||
feigenbauma |
Second Feigenbaum's constant | |||
glaisher |
Glaisher-Khinkelin's constant | |||
khinchin |
Khinchin's constant | |||
mertens |
Meissel-Mertens's constant |
The constants, their values and their units are taken from https://en.wikipedia.org/wiki/List_of_physical_constants.
chplot name |
Quantity | Symbol |
chplot value (in SI units) |
Units |
---|---|---|---|---|
a0 |
Bohr's radius | |||
alpha |
Fine-structure constant | --- | ||
b |
Wien's wavelength displacement law constant | |||
bp |
Wien's entropy displacement law constant | |||
bp |
Wien's frequency displacement law constant | |||
c |
Speed of light in vacuum | |||
c1 |
First radiation constant | |||
c1L |
Second radiation constant | |||
c2 |
Second radiation constant | |||
dnuCs |
Hyperfine transistion frequency of Cesium-133 | |||
ec |
Elementary charge | |||
Eh |
Hartree's energy | |||
epsilon0 eps0
|
Vacuum electric permittivity | |||
eV |
Electronvolt value in Joule | |||
F |
Faraday's constant | |||
G |
Gravitational constant | |||
g |
Gravity of Earth | |||
G0 |
Conductance quantum | |||
ge |
Electron g-factor | --- | ||
GF0 |
Fermi coupling constant Reduced Fermi constant |
|||
gmu |
Muon g-factor | --- | ||
gP |
Proton g-factor | --- | ||
h |
Planck's constant | |||
hb |
Reduced Planck's constant | |||
kB |
Boltzmann's constant |
|
||
ke |
Coulomb's constant | |||
KJ |
Josephson's constant | |||
m12C |
Atomic mass of carbon-12 | |||
M12C |
Molar mass of carbon-12 | |||
me |
Electron mass | |||
mmu |
Muon mass | |||
mn |
Neutron mass | |||
mp |
Proton mass | |||
mt |
Top quark mass | |||
mtau |
Tau mass | |||
mu |
Atomic mass constant | |||
Mu |
Molar mass constant | |||
mu0 |
Vacuum magnetic parmeability | |||
muB |
Bohr's magneton | |||
muN |
Nuclear magneton | |||
NA |
Avogadro constant | |||
R |
Molar gas constant | |||
re |
Classical electron radius | |||
Rinf |
Rydberg's constant | |||
RK |
Von Klitzing's constant | |||
Ry |
Rydberg's unit of energy | |||
sigma |
Stefan-Boltzmann's constant | |||
sigmae |
Thomson's cross section | |||
VmSi |
Molar volume of silicon | |||
Z0 |
Characteristic impedance of vacuum |
All the planets data are taken from : https://nssdc.gsfc.nasa.gov.
chplot name |
Quantity |
chplot value (in SI units) |
Units |
---|---|---|---|
Msun |
Sun mass | ||
Mmercury |
Mercury mass | ||
Mvenus |
Venus mass | ||
Mearth |
Earth mass | ||
Mmoon |
Moon mass | ||
Mmars |
Mars mass | ||
Mjupiter |
Jupiter mass | ||
Msaturn |
Saturn mass | ||
Muranus |
Uranus mass | ||
Mneptune |
Neptune mass | ||
Mpluto |
Pluto mass | ||
Mcharon |
Charon mass | ||
Rsun |
Sun volumetric mean radius | ||
Rmercury |
Mercury volumetric mean radius | ||
Rvenus |
Venus volumetric mean radius | ||
Rearth |
Earth volumetric mean radius | ||
Rmoon |
Moon volumetric mean radius | ||
Rmars |
Mars volumetric mean radius | ||
Rjupiter |
Jupiter volumetric mean radius | ||
Rsaturn |
Saturn volumetric mean radius | ||
Ruranus |
Uranus volumetric mean radius | ||
Rneptune |
Neptune volumetric mean radius | ||
Rpluto |
Pluto volumetric mean radius | ||
Rcharon |
Charon volumetric mean radius | ||
AU |
Astronomical unit in meters | ||
ly |
Light-year in meters | ||
pc |
Parsec in meters |
Documentation: https://docs.python.org/3/library/math.html
chplot name(s) |
math name |
Number of arguments | Notes |
---|---|---|---|
acos |
acos |
1 | |
acosh |
acosh |
1 | |
asin |
asin |
1 | |
asinh |
asinh |
1 | |
atan |
atan |
1 | |
atanh |
atanh |
1 | |
atan2 |
atan2 |
2 | |
cbrt |
cbrt |
1 | |
ceil |
ceil |
1 | |
copysign |
copysign |
2 | |
cos |
cos |
1 | |
cosh |
cosh |
1 | |
degrees |
degrees |
1 | |
dist |
dist |
4 | dist(x1, y1, x2, y2) is interpreted as math.dist((x1, y1), (x2, y2)) |
erf |
erf |
1 | |
erfc |
erfc |
1 | |
exp |
exp |
1 | |
expm1 |
expm1 |
1 | |
floor |
floor |
1 | |
fmod |
fmod |
2 | |
gamma |
gamma |
1 | |
hypot |
hypot |
2 | |
lgamma lngamma |
lgamma |
1 | |
log ln |
log |
1 | |
log10 |
log10 |
1 | |
log1p |
log1p |
1 | |
log2 |
log2 |
1 | |
radians |
radians |
1 | |
remainder |
remainder |
2 | |
sin |
sin |
1 | |
sinh |
sinh |
1 | |
sqrt |
sqrt |
1 | |
tan |
tan |
1 | |
trunc |
trunc |
1 |
Documentation: https://docs.scipy.org/doc/scipy/reference/special.html
chplot name(s) |
scipy.special name |
Number of arguments | Notes |
---|---|---|---|
agm |
agm |
2 | |
Ai |
airy |
1 | First output |
Aip |
airy |
1 | Second output |
bei |
bei |
1 | |
beip |
beip |
1 | |
ber |
ber |
1 | |
berp |
berp |
1 | |
beta |
beta |
2 | |
betainc |
betainc |
3 | |
betaincinv |
betaincinv |
3 | |
betaln |
betaln |
2 | |
Bi |
airy |
1 | Third output |
binom binomial |
binom |
2 | |
Bip |
airy |
1 | Fourth output |
Chi |
shichi |
1 | Second output |
Ci |
sici |
1 | Second output |
digamma |
digamma |
1 | |
eAi |
airye |
1 | First output |
eAip |
airye |
1 | Second output |
eBi |
airye |
1 | Third output |
eBip |
airye |
1 | Fourth output |
ellipe |
ellipe |
1 | |
ellipeinc |
ellipeinc |
2 | |
ellipk |
ellipk |
1 | |
ellipkinc |
ellipkinc |
2 | |
elliprc |
elliprc |
2 | |
elliprd |
elliprd |
3 | |
elliprf |
elliprf |
3 | |
elliprg |
elliprg |
3 | |
elliprj |
elliprj |
4 | |
erfcinv |
erfcinv |
1 | |
erfi |
erfi |
1 | |
erfinv |
erfinv |
1 | |
factorial fac |
factorial |
1 | |
fresnelc |
fresnel |
1 | Second output |
fresnels |
fresnel |
1 | First output |
gammainc |
gammainc |
2 | |
gammaincc |
gammaincc |
2 | |
gammainccinv |
gammainccinv |
2 | |
gammaincinv |
gammaincinv |
2 | |
hurwitz hurwitzzeta |
zeta |
2 | |
hyp0f1 |
hyp0f1 |
2 | |
hyp1f1 |
hyp1f1 |
3 | |
hyp2f1 |
hyp2f1 |
4 | |
hyperu |
hyperu |
3 | |
it2struve0 |
it2struve0 |
1 | |
itmodstruve0 |
itmodstruve0 |
1 | |
itstruve0 |
itstruve0 |
1 | |
iv besseli |
iv |
2 | |
jv besselj |
jv |
2 | |
kei |
kei |
1 | |
keip |
keip |
1 | |
ker |
ker |
1 | |
kerp |
kerp |
1 | |
kv besselk |
kv |
2 | |
lambertw |
lambertw |
1 | |
loggamma |
loggamma |
1 | |
modstruve struvel |
modstruve |
2 | |
psi |
psi |
1 | |
rgamma |
rgamma |
1 | |
Shi |
shichi |
1 | First output |
Si |
sici |
1 | First output |
sincpi |
sinc |
1 | |
struve struveh |
struve |
2 | |
yv bessely |
yv |
2 | |
zeta |
zeta |
1 |
Documentation: https://mpmath.org/doc/current/
chplot name(s) |
mpmath name |
Number of arguments | Notes |
---|---|---|---|
acot |
acot |
1 | |
acoth |
acoth |
1 | |
acsc |
acsc |
1 | |
acsch |
acsch |
1 | |
altzeta eta |
altzeta |
1 | |
angerj |
angerj |
2 | |
asec |
asec |
1 | |
asech |
asech |
1 | |
backlunds |
backlunds |
1 | |
barnesg |
barnesg |
1 | |
betainc2 |
betainc |
4 | |
chebyt |
chebyt |
2 | |
chebyu |
chebyu |
2 | |
clcos |
clcos |
2 | |
clsin |
clsin |
2 | |
cospi cospi |
cospi |
1 | |
cot |
cot |
1 | |
coth |
coth |
1 | |
coulombc |
coulombc |
2 | |
coulombf |
coulombf |
3 | |
coulombg |
coulombg |
3 | |
csc |
csc |
1 | |
csch |
csch |
1 | |
Ei |
ei |
1 | |
ellipf |
ellipf |
2 | |
ellippi |
ellippi |
3 | |
fac2 |
fac2 |
1 | |
ff |
ff |
1 | |
fib |
fib |
1 | |
fibonacci |
fibonacci |
1 | |
gammainc2 |
gammainc |
3 | |
gegenbauer |
gegenbauer |
3 | |
harmonic |
harmonic |
1 | |
hermite |
hermite |
2 | |
hyp1f2 |
hyp1f2 |
4 | |
hyp2f0 |
hyp2f0 |
3 | |
hyp2f3 |
hyp2f3 |
5 | |
hyp3f2 |
hyp3f2 |
6 | |
hyperfac |
hyperfac |
1 | |
jacobi |
jacobi |
4 | |
laguerre |
laguerre |
3 | |
legendre |
legendre |
2 | |
legenp |
legenp |
3 | |
legenq |
legenq |
3 | |
lerchphi |
lerchphi |
3 | |
li |
li |
1 | Computes li(x, offset=False) |
Li |
li |
1 | Computes li(x, offset=True) |
lommels1 |
lommels1 |
3 | |
lommels2 |
lommels2 |
3 | |
nzetazeros |
nzeros |
1 | |
pcfd |
pcfd |
2 | |
pcfu |
pcfu |
2 | |
pcfv |
pcfv |
2 | |
pcfw |
pcfw |
2 | |
polyexp |
polyexp |
2 | |
polylog |
polylog |
2 | |
primepi |
primepi |
1 | |
primezeta |
primezeta |
1 | |
rf |
rf |
1 | |
riemannr |
riemannr |
1 | |
scorergi |
scorergi |
1 | |
scorerhi |
scorerhi |
1 | |
sec |
sec |
1 | |
sech |
sech |
1 | |
secondzeta |
secondzeta |
1 | |
siegeltheta |
siegeltheta |
1 | |
siegelz |
siegelz |
1 | |
sinc |
sinc |
1 | |
stieltjes |
stieltjes |
1 | |
superfac |
superfac |
1 | |
W |
lambertw |
1 | |
webere |
webere |
2 | |
whitm |
whitm |
3 | |
whitw |
whitw |
3 |
chplot name |
Name | Arguments | Expression |
---|---|---|---|
normpdf |
Normal distribution PDF | ||
normcdf |
Normal distribution CDF | ||
unormpdf |
Unit normal distribution PDF | ||
unormcdf |
Unit normal distribution CDF | ||
tripdf |
Triangle distribution PDF |
|
|
tricdf |
Triangle distribution CDF |
|
|
uniformpdf |
Uniform distribution PDF |
|
|
uniformcdf |
Uniform distribution CDF |
|
|
exppdf |
Exponential distribution PDF |
|
|
expcdf |
Exponential distribution CDF |
|
|
studentpdf |
Student's t-distribution PDF | Wikipedia | |
studentcdf |
Student's t-distribution CDF | Wikipedia | |
betapdf |
Beta distribution PDF | Wikipedia | |
betacdf |
Beta distribution CDF | Wikipedia | |
chi2pdf khi2pdf
|
Chi-squared distribution PDF | Wikipedia | |
chi2cdf khi2cdf
|
Chi-squared distribution CDF | Wikipedia | |
gammapdf |
Gamma distribution PDF | Wikipedia | |
gammacdf |
Gamma distribution CDF | Wikipedia | |
cauchypdf |
Cauchy distribution PDF | ||
cauchycdf |
Cauchy distribution CDF |
To use the (
In this table,
chplot name |
Arguments | Expression |
---|---|---|
relu ramp
|
|
|
lrelu |
|
|
sigm sigmoid
|
||
sign sgn
|
|
|
lerp |
||
lerpt |
||
heaviside |
|
|
rect |
|
|
triangle tri
|
|
|
sawtooth |
||
squarewave sqwave
|
|
|
trianglewave triwave
|
|
|
abs |
||
min |
||
min3 |
||
min4 |
||
max |
||
max3 |
||
max4 |
||
if |
|
|
ifn |
|
|
ifz |
|
|
in |
|
|
out |
|
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.
Click to reveal
_ |
a0 |
abs |
acos |
acosh |
acot |
acoth |
acsc |
acsch |
agm |
Ai |
Aip |
alpha |
altzeta |
angerj |
apery |
asec |
asech |
asin |
asinh |
atan |
atan2 |
atanh |
AU |
b |
backlunds |
barnesg |
bei |
beip |
bent |
ber |
berp |
besseli |
besselj |
besselk |
bessely |
beta |
betacdf |
betainc |
betainc2 |
betaincinv |
betaln |
betapdf |
Bi |
binom |
binomial |
Bip |
bp |
brun |
c |
c1 |
c1L |
c2 |
catalan |
cauchycdf |
cauchypdf |
cbrt |
ceil |
chebyt |
chebyu |
Chi |
chi2cdf |
chi2pdf |
Ci |
clcos |
clsin |
copysign |
cos |
cosh |
cospi |
cot |
coth |
coulombc |
coulombf |
coulombg |
csc |
csch |
degrees |
digamma |
dist |
dnuCs |
e |
eAi |
eAip |
eBi |
eBip |
ec |
Eh |
Ei |
ellipe |
ellipeinc |
ellipf |
ellipk |
ellipkinc |
ellippi |
elliprc |
elliprd |
elliprf |
elliprg |
elliprj |
em |
eps0 |
epsilon0 |
erf |
erfc |
erfcinv |
erfi |
erfinv |
eta |
eV |
exp |
expcdf |
expm1 |
exppdf |
F |
fac |
fac2 |
factorial |
feigenbauma |
feigenbaumd |
ff |
fib |
fibonacci |
floor |
fmod |
fresnelc |
fresnels |
G |
g |
G0 |
ga |
gamma |
gammacdf |
gammainc |
gammainc2 |
gammaincc |
gammainccinv |
gammaincinv |
gammapdf |
ge |
gegenbauer |
GF0 |
glaisher |
gmu |
gP |
h |
harmonic |
hb |
heaviside |
hermite |
hurwitz |
hurwitzzeta |
hyp0f1 |
hyp1f1 |
hyp1f2 |
hyp2f0 |
hyp2f1 |
hyp2f3 |
hyp3f2 |
hyperfac |
hyperu |
hypot |
if |
ifn |
ifz |
in |
inf |
it2struve0 |
itmodstruve0 |
itstruve0 |
iv |
jacobi |
jv |
kB |
ke |
kei |
keip |
ker |
kerp |
khi2cdf |
khi2pdf |
khinchin |
KJ |
kv |
laguerre |
lambert |
lambertw |
legendre |
legenp |
legenq |
lerchphi |
lerp |
lerpt |
lgamma |
Li |
li |
ln |
lngamma |
log |
log10 |
log1p |
log2 |
loggamma |
lommels1 |
lommels2 |
lrelu |
ly |
m12C |
M12C |
max |
max3 |
max4 |
Mcharon |
me |
Mearth |
mertens |
min |
min3 |
min4 |
Mjupiter |
Mmars |
Mmercury |
Mmoon |
mmu |
mn |
Mneptune |
modstruve |
mp |
Mpluto |
Msaturn |
Msun |
mt |
mtau |
mu |
Mu |
mu0 |
muB |
muN |
Muranus |
Mvenus |
NA |
nan |
normcdf |
normpdf |
nzetazeros |
out |
pc |
pcfd |
pcfu |
pcfv |
pcfw |
phi |
pi |
polyexp |
polylog |
primepi |
primezeta |
psi |
R |
radians |
ramp |
Rcharon |
re |
Rearth |
rect |
relu |
remainder |
rf |
rgamma |
riemannr |
Rinf |
Rjupiter |
RK |
Rmars |
Rmercury |
Rmoon |
Rneptune |
Rpluto |
Rsaturn |
Rsun |
Ruranus |
Rvenus |
Ry |
sawtooth |
scorergi |
scorerhi |
sec |
sech |
secondzeta |
sgn |
Shi |
Si |
siegeltheta |
siegelz |
sigm |
sigma |
sigmae |
sigmoid |
sign |
sin |
sinc |
sincpi |
sinh |
sqrt |
sqrt2 |
squarewave |
sqwave |
stieltjes |
struve |
struveh |
struvel |
studentcdf |
studentpdf |
superfac |
tan |
tanh |
tau |
tri |
triangle |
trianglewave |
tricdf |
tripdf |
triwave |
trunc |
uniformcdf |
uniformpdf |
unormcdf |
unormpdf |
VmSi |
W |
webere |
whitm |
whitw |
yv |
Z0 |
zeta |
Every file referenced in any commands can be found in the resources folder.
python -m chplot x
python -m chplot x " -x+1" "x^2"
python -m chplot resources/files/equations.txt
python -m chplot t(t-1) -v t
python -m chplot sin(var*3) -v var
Overriding constant with variable:
python -m chplot c
python -m chplot c -v c
The expression in the first command is interpreted as
python -m chplot "x*1.2e-1"
python -m chplot "x*1.2e-1" --no-sn
Using expressions in the horizontal axis bounds:
python -m chplot "x^2+x" -x -3 3
python -m chplot x -x " -sqrt(2)" "zeta(3)"
Using expressions in the vertical axis bounds and restricting the graph:
python -m chplot fac(x) -x 0 6
python -m chplot fac(x) -x 0 6 -y 0.5 1.5
The -i
parameter removes the line between points.
python -m chplot cos(x) -x 0 10 -n 20
python -m chplot cos(x) -x 0 10 -i
python -m chplot sqrt(x) -x 0 100 -i
python -m chplot sqrt(x) -x 0 10 --dis 10 -n 35
python -m chplot "2^x" -x 1 100 -ylog
python -m chplot "ln(x)" -x 1 100 -xlog
Log axis will adjust the bounds to remove negative points:
python -m chplot "x^3.5" -x 1 100 -xlog -ylog
python -m chplot "x" -x -5 5 -xlog
python -m chplot "x" -x -5 -1 -xlog
The 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 values
The 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
python -m chplot "sin(x)+10" -x 1 10pi
python -m chplot "sin(x)+10" -x 1 10pi -z
python -m chplot zeta(x) -x 1 10 -y 0 3
python -m chplot zeta(x) -x 1 10 -y 0 3 -xl "Variable x" -yl "Zeta(x)" -t "Zeta function on [1 ; 10]" -rl
python -m chplot cbrt(x) --square
python -m chplot cbrt(x) -lw 5
If a constant requires another one, define it after:
python -m chplot a*x+b -c a=2 b=7
python -m chplot "a*x^2-b*x+1" -c a=8pi/19 "b=a^2-1"
Constants can also be an expression, or come from a file:
python -m chplot cos(a*x) -c "a=(sqrt(2) - zeta(3)) / sin(1.5)" -x 0 50
python -m chplot "a*x^3+b*x^2+c*x+d" -c resources\files\constants.txt -x -10 10
All the CSV format are summarized in the CSV files format section.
python -m chplot -f resources\files\data.csv
python -m chplot x "x(x+1)" "x(x+1)(x+2)/2" "x(x+1)(x+2)(x+3)/6" -d resources\files\saved_data.csv
The data can be found in the saved_data.csv file.
The file functions.py
must be in the directory from where the command is executed.
python -m chplot "frac(x)+3" "is_prime(x)" "rnd(x, x/2)" -p functions.py -x 0 10
python -m chplot sin(x) -x -7 7 --zeros
python -m chplot "x^2-2" "in(x, 0.2, 0.3, 0, -2x+1)" -x 0 2 --zeros
The result of these commands (besides the plot) are the following. The first are the zeros of the function
===== ZEROS OF THE FUNCTIONS =====
Note that non-continuous functions may give false zeros. Furthermore, some zeros may be missing if the graph is tangent to the x-axis.
- On the interval [-7.0 ; 7.0], the function f(x) = sin(x) equals zero...
at x = -6.2831853072
at x = -3.1415926536
at x = 0.0
at x = 3.1415926536
at x = 6.2831853072
===== ZEROS OF THE FUNCTIONS =====
Note that non-continuous functions may give false zeros. Furthermore, some zeros may be missing if the graph is tangent to the x-axis.
- On the interval [0.0 ; 2.0], the function f(x) = x^2-2 equals zero...
at x = 1.4142135624
- On the interval [0.0 ; 2.0], the function f(x) = in(x, 0.2, 0.3, 0, -2x+1) equals zero...
on [0.2 ; 0.3]
at x = 0.5
python -m chplot "1/x" -x 1 e --integral
python -m chplot "x^2" "exp(x)" --integral
The result of these commands (besides the plot) are the following.$$\int_1^e\frac{dx}{x} = 1$$
===== INTEGRALS OF THE FUNCTIONS =====
Note that the more points, the smallest the error and that floating point numbers may introduce errors. Furthermore, discontinuous functions may indicate really huge error margins.
- ∫f(x)dx = 1.0000000021279944
where f(x) = 1/x on [1.0 ; 2.718]
===== INTEGRALS OF THE FUNCTIONS =====
Note that the more points, the smallest the error and that floating point numbers may introduce errors. Furthermore, discontinuous functions may indicate really huge error margins.
- ∫f(x)dx = 0.33333333499999834
where f(x) = x^2 on [0.0 ; 1.0]
- ∫f(x)dx = 1.7182818298909472
where f(x) = exp(x) on [0.0 ; 1.0]
The second command illustrates the instability of the higher order derivatives.
python -m chplot "sin(x)" --deriv 1 2 3 4 -x 0 4pi
python -m chplot "exp(x)" --deriv 1 4 7 -n 100000
Synergy between --deriv
and --zeros
/--integral
.
python -m chplot "x^2+2" -x -3 3 --deriv 1 --zeros --integral
===== ZEROS OF THE FUNCTIONS =====
Note that non-continuous functions may give false zeros. Furthermore, some zeros may be missing if the graph is tangent to the x-axis.
Furthermore, on derivatives and file data, zeros are approximated using linear interpolation, and may be far from their real values.
- On the interval [-3.0 ; 3.0], the function f(x) = x^2+2 never equals zero.
- On the interval [-2.998 ; 2.998], the function f(x) = d/dx * (x^2+2) equals zero...
at x = 0.0
===== INTEGRALS OF THE FUNCTIONS =====
Note that the more points, the smallest the error and that floating point numbers may introduce errors. Furthermore, discontinuous functions may indicate really huge error margins.
The x-axis limits on derivatives are slightly tighter because of the algorithm used. This may be counteracted by adding more points.
- ∫f(x)dx = 30.000000359996804
where f(x) = x^2+2 on [-3.0 ; 3.0]
- ∫f(x)dx = 6.18809004038144e-14
where f(x) = d/dx * (x^2+2) on [-2.998 ; 2.998]
Default keyword usable in the CLI.
python -m chplot "sin(x)" " -exp(x)" --reg lin
===== REGRESSION COEFFICIENTS OF THE FUNCTIONS =====
Regression function: reg(x) = a * x + b
- Function f(x) = sin(x)
Coefficients:
a = 0.85583 (exact 0.8558336726408089)
b = 0.03178 (exact 0.031776961574734974)
Accuracy on [0.000 ; 1.000]:
R2 = 0.9948573993162803
|err| <= 0.046139649407647365
|rel err| <= 317.625449951033
Copyable expression:
f(x) = (0.8558336726408089) * x + (0.031776961574734974)
- Function f(x) = -exp(x)
Coefficients:
a = -1.69032 (exact -1.6903174201716293)
b = -0.87314 (exact -0.8731372047610497)
Accuracy on [0.000 ; 1.000]:
R2 = 0.9837173025833181
|err| <= 0.15482720352636603
|rel err| <= 0.12686279523895028
Copyable expression:
f(x) = (-1.6903174201716293) * x + (-0.8731372047610497)
Arbitrary expression for regression (here:
python -m chplot "x" "x^2-3x+2" -x 1 2 --reg "_ra + _rb/x + _rc/x^2"
===== REGRESSION COEFFICIENTS OF THE FUNCTIONS =====
Regression function: reg(x) = a + b/x + c/x^2
- Function f(x) = x
Coefficients:
a = 4.32347 (exact 4.323472460240034)
b = -6.08251 (exact -6.082510526066791)
c = 2.7852 (exact 2.7852046542434103)
Accuracy on [1.000 ; 2.000]:
R2 = 0.9990492201082051
|err| <= 0.026166588416653536
|rel err| <= 0.026166588416653536
Copyable expression:
f(x) = (4.323472460240034) + (-6.082510526066791)/x + (2.7852046542434103)/x^2
- Function f(x) = x^2-3x+2
Coefficients:
a = 1.70398 (exact 1.7039810825081398)
b = -5.44646 (exact -5.446461246934391)
c = 3.8091 (exact 3.809103050454299)
Accuracy on [1.000 ; 2.000]:
R2 = 0.8852455638434826
|err| <= 0.06697377834548113
|rel err| <= 669.2141410779176
Copyable expression:
f(x) = (1.7039810825081398) + (-5.446461246934391)/x + (3.809103050454299)/x^2
Regression on file data.
python -m chplot -f resources\files\data.csv --reg poly2
===== REGRESSION COEFFICIENTS OF THE FUNCTIONS =====
Regression function: reg(x) = a2 * x^2 + a1 * x + a0
- Function f(x) = data.csv - vy(t)
Coefficients:
a2 = 0.0 (exact -5.0979039530237654e-08)
a1 = -9.81 (exact -9.809999897491432)
a0 = 10.0 (exact 9.999999965897445)
Accuracy on [0.000 ; 2.030]:
R2 = 1.0
|err| <= 3.608967524826312e-08
|rel err| <= 2.809290005481242e-06
Copyable expression:
f(x) = (-5.0979039530237654e-08) * x^2 + (-9.809999897491432) * x + (9.999999965897445)
- Function f(x) = data.csv - y(t)
Coefficients:
a2 = -4.905 (exact -4.904999983961847)
a1 = 10.0 (exact 9.999999961872113)
a0 = 0.0 (exact 1.7338066957762713e-08)
Accuracy on [0.000 ; 2.030]:
R2 = 1.0
|err| <= 1.7338066957762713e-08
|rel err| <= 1.7041982824835924e-07
Copyable expression:
f(x) = (-4.904999983961847) * x^2 + (9.999999961872113) * x + (1.7338066957762713e-08)
Synergy between --reg
and --deriv
/--zeros
/--integral
.
python -m chplot log2(x) -x 1 3 --deriv 1 --reg lin --zeros --integral
===== REGRESSION COEFFICIENTS OF THE FUNCTIONS =====
Regression function: reg(x) = a * x + b
- Function f(x) = log2(x)
Coefficients:
a = 0.76193 (exact 0.7619286641417374)
b = -0.58912 (exact -0.5891228449973627)
Accuracy on [1.000 ; 3.000]:
R2 = 0.9808243468285833
|err| <= 0.17280581914437476
|rel err| <= 598.4874010749205
Copyable expression:
f(x) = (0.7619286641417374) * x + (-0.5891228449973627)
===== ZEROS OF THE FUNCTIONS =====
Note that non-continuous functions may give false zeros. Furthermore, some zeros may be missing if the graph is tangent to the x-axis.
Furthermore, on derivatives and file data, zeros are approximated using linear interpolation, and may be far from their real values.
- On the interval [1.0 ; 3.0], the function f(x) = log2(x) equals zero...
at x = 1.0
- On the interval [1.0 ; 3.0], the function f(x) = Regression [log2(x)] never equals zero.
- On the interval [1.001 ; 2.999], the function f(x) = d/dx * (log2(x)) never equals zero.
- On the interval [1.001 ; 2.999], the function f(x) = d/dx * (Regression [log2(x)]) never equals zero.
===== INTEGRALS OF THE FUNCTIONS =====
Note that the more points, the smallest the error and that floating point numbers may introduce errors. Furthermore, discontinuous functions may indicate really huge error margins.
The x-axis limits on derivatives are slightly tighter because of the algorithm used. This may be counteracted by adding more points.
- ∫f(x)dx = 1.8694974171793488
where f(x) = log2(x) on [1.0 ; 3.0]
- ∫f(x)dx = 1.8694689665720188
where f(x) = Regression [log2(x)] on [1.0 ; 3.0]
- ∫f(x)dx = 1.583424040388957
where f(x) = d/dx * (log2(x)) on [1.001 ; 2.999]
- ∫f(x)dx = 1.5226382424208345
where f(x) = d/dx * (Regression [log2(x)]) on [1.001 ; 2.999]
- Parallelizing computation of expressions.