Symbolic expression representing the function of one variable
to be plotted.
Numerical function of one variable, supporting vectorization.
In this case the following keyword arguments are not supported:
params, sum_bound.
range(symbol, min, max)
A 3-tuple denoting the range of the x variable. Default values:
min=-10 and max=10.
labelstr, optional
The label to be shown in the legend. If not provided, the string
representation of expr will be used.
rendering_kwdict, optional
A dictionary of keywords/values which is passed to the backend’s
function to customize the appearance of lines. Refer to the
plotting library (backend) manual for more informations.
adaptivebool, optional
Setting adaptive=True activates the adaptive algorithm
implemented in [1] to create smooth plots. Use adaptive_goal
and loss_fn to further customize the output.
The default value is False, which uses an uniform sampling
strategy, where the number of discretization points is specified by
the n keyword argument.
adaptive_goalcallable, int, float or None
Controls the “smoothness” of the evaluation. Possible values:
None (default): it will use the following goal:
lambdal:l.loss()<0.01
number (int or float). The lower the number, the more
evaluation points. This number will be used in the following goal:
lambdal:l.loss()<number
callable: a function requiring one input element, the learner. It
must return a float number. Refer to [1] for more information.
aspect(float, float) or str, optional
Set the aspect ratio of the plot. The value depends on the backend
being used. Read that backend’s documentation to find out the
possible values.
axis_center(float, float), optional
Tuple of two floats denoting the coordinates of the center or
{‘center’, ‘auto’}. Only available with MatplotlibBackend.
backendPlot, optional
A subclass of Plot, which will perform the rendering.
Default to MatplotlibBackend.
color_funccallable or Expr, optional
Define the line color mapping. It can either be:
A numerical function of 2 variables, x, y (the points computed by
the internal algorithm) supporting vectorization.
A symbolic expression having at most as many free symbols as
expr.
None: the default value (no color mapping).
detect_polesboolean, optional
Chose whether to detect and correctly plot poles.
Defaulto to False. To improve detection, increase the number of
discretization points n and/or change the value of eps.
epsfloat, optional
An arbitrary small value used by the detect_poles algorithm.
Default value to 0.1. Before changing this value, it is recommended to
increase the number of discretization points.
force_real_evalboolean, optional
Default to False, with which the numerical evaluation is attempted
over a complex domain, which is slower but produces correct results.
Set this to True if performance is of paramount importance, but be
aware that it might produce wrong results. It only works with
adaptive=False.
is_pointboolean, optional
Default to False, which will render a line connecting all the points.
If True, a scatter plot will be generated.
is_filledboolean, optional
Default to True, which will render empty circular markers. It only
works if is_point=True.
If False, filled circular markers will be rendered.
labelstr or list/tuple, optional
The label to be shown in the legend. If not provided, the string
representation of expr will be used. The number of labels must be
equal to the number of expressions.
loss_fncallable or None
The loss function to be used by the adaptive learner.
Possible values:
None (default): it will use the default_loss from the
adaptive module.
callable : Refer to [1] for more information. Specifically,
look at adaptive.learner.learner1D to find more loss functions.
nint, optional
Used when the adaptive=False: the function is uniformly
sampled at n number of points. Default value to 1000.
If the adaptive=True, this parameter will be ignored.
only_integersboolean, optional
Default to False. If True, discretize the domain with integer
numbers. It only works when adaptive=False.
When only_integers=True, the number of discretization points is
choosen by the algorithm.
paramsdict
A dictionary mapping symbols to parameters. This keyword argument
enables the interactive-widgets plot, which doesn’t support the
adaptive algorithm (meaning it will use adaptive=False).
Learn more by reading the documentation of iplot.
rendering_kwdict or list of dicts, optional
A dictionary of keywords/values which is passed to the backend’s
function to customize the appearance of lines. Refer to the
plotting library (backend) manual for more informations.
If a list of dictionaries is provided, the number of dictionaries must
be equal to the number of expressions.
is_polarboolean, optional
Default to False. If True, requests the backend to use a 2D polar
chart.
showbool, optional
The default value is set to True. Set show to False and
the function will not display the plot. The returned instance of
the Plot class can then be used to save or display the plot
by calling the save() and show() methods respectively.
size(float, float), optional
A tuple in the form (width, height) to specify the size of
the overall figure. The default value is set to None, meaning
the size will be set by the backend.
stepsboolean, optional
Default to False. If True, connects consecutive points with
steps rather than straight segments.
sum_boundint, optional
When plotting sums, the expression will be pre-processed in order
to replace lower/upper bounds set to +/- infinity with this +/-
numerical value. Default value to 1000. Note: the higher this number,
the slower the evaluation.
titlestr, optional
Title of the plot.
tx, tycallable, optional
Apply a numerical function to the discretized x-direction or to the
output of the numerical evaluation, the y-direction.
use_latexboolean, optional
Turn on/off the rendering of latex labels. If the backend doesn’t
support latex, it will render the string representations instead.
xlabel, ylabelstr, optional
Labels for the x-axis or y-axis, respectively.
xscale, yscale‘linear’ or ‘log’, optional
Sets the scaling of the x-axis or y-axis, respectively.
Default to 'linear'.
xlim(float, float), optional
Denotes the x-axis limits, (min,max), visible in the chart.
Note that the function is still being evaluated over the specified
range.
ylim(float, float), optional
Denotes the y-axis limits, (min,max), visible in the chart.
Multiple functions over the same range with custom rendering options:
>>> plot(x,log(x),exp(x),(x,-3,3),aspect="equal",ylim=(-3,3),... rendering_kw=[{},{"linestyle":"--"},{"linestyle":":"}])Plot object containing:[0]: cartesian line: x for x over (-3.0, 3.0)[1]: cartesian line: log(x) for x over (-3.0, 3.0)[2]: cartesian line: exp(x) for x over (-3.0, 3.0)
Plotting a summation in which the free symbol of the expression is
used in the lower/upper bounds. Here, the discretization variable must
assume integer values:
>>> expr=Sum(1/x,(x,1,y))>>> plot(expr,(y,2,10),adaptive=False,... is_point=True,is_filled=True,title="$%s$"%latex(expr))Plot object containing:[0]: cartesian line: Sum(1/x, (x, 1, y)) for y over (2.0, 10.0)
Using an adaptive algorithm, detect singularities and apply a
transformation function to the discretized domain in order to convert
radians to degrees:
>>> importnumpyasnp>>> plot(tan(x),(x,-1.5*pi,1.5*pi),... adaptive=True,adaptive_goal=0.001,... detect_poles=True,tx=np.rad2deg,ylim=(-7,7),... xlabel="x [deg]")Plot object containing:[0]: cartesian line: tan(x) for x over (-4.71238898038469, 4.71238898038469)
detect singularities by setting adaptive=False (better performance),
increasing the number of discretization points (in order to have
‘vertical’ segments on the lines) and reducing the threshold for the
singularity-detection algorithm.
application of color function.
>>> importnumpyasnp>>> expr=1/cos(10*x)+5*sin(x)>>> defcf(x,y):... # map a colormap to the distance from the origin... d=np.sqrt(x**2+y**2)... # visibility of the plot is limited: ylim=(-10, 10). However,... # some of the y-values computed by the function are much higher... # (or lower). Filter them out in order to have the entire... # colormap spectrum visible in the plot.... offset=12# 12 > 10 (safety margin)... d[(y>offset)|(y<-offset)]=0... returnd>>> p1=plot(expr,(x,-5,5),... "distance from (0, 0)",{"cmap":"plasma"},... ylim=(-10,10),adaptive=False,detect_poles=True,n=3e04,... eps=1e-04,color_func=cf,title="$%s$"%latex(expr))
Interactive-widget plot of an oscillator. Refer to the interactive
sub-module documentation to learn more about the params dictionary.
This plot illustrates:
plotting multiple expressions, each one with its own label and
rendering options.
the use of prange (parametric plotting range).
the use of the params dictionary to specify sliders in
their basic form: (default, min, max).
fromsympyimport*fromspbimport*x,a,b,c,n=symbols("x, a, b, c, n")plot((cos(a*x+b)*exp(-c*x),"oscillator"),(exp(-c*x),"upper limit",{"linestyle":":"}),(-exp(-c*x),"lower limit",{"linestyle":":"}),prange(x,0,n*pi),params={a:(1,0,10),# frequencyb:(0,0,2*pi),# phasec:(0.25,0,1),# dampingn:(2,0,4)# multiple of pi},ylim=(-1.25,1.25),use_latex=False)
The expression representing x component of the parametric
function. It can be a:
Symbolic expression representing the function of one variable
to be plotted.
Numerical function of one variable, supporting vectorization.
In this case the following keyword arguments are not supported:
params.
expr_yExpr
The expression representing y component of the parametric
function. It can be a:
Symbolic expression representing the function of one variable
to be plotted.
Numerical function of one variable, supporting vectorization.
In this case the following keyword arguments are not supported:
params.
range(symbol, min, max)
A 3-tuple denoting the parameter symbol, start and stop. For
example, (u,0,5). If the range is not specified, then a
default range of (-10, 10) is used.
However, if the arguments are specified as
(expr_x,expr_y,range),..., you must specify the ranges
for each expressions manually.
labelstr, optional
The label to be shown in the legend. If not provided, the string
representation of expr_x and expr_y will be used.
rendering_kwdict, optional
A dictionary of keywords/values which is passed to the backend’s
function to customize the appearance of lines. Refer to the
plotting library (backend) manual for more informations.
adaptivebool, optional
Setting adaptive=True activates the adaptive algorithm
implemented in [2] to create smooth plots. Use adaptive_goal
and loss_fn to further customize the output.
The default value is False, which uses an uniform sampling
strategy, where the number of discretization points is specified by
the n keyword argument.
adaptive_goalcallable, int, float or None
Controls the “smoothness” of the evaluation. Possible values:
None (default): it will use the following goal:
lambdal:l.loss()<0.01
number (int or float). The lower the number, the more
evaluation points. This number will be used in the following goal:
lambdal:l.loss()<number
callable: a function requiring one input element, the learner. It
must return a float number. Refer to [2] for more information.
aspect(float, float) or str, optional
Set the aspect ratio of the plot. The value depends on the backend
being used. Read that backend’s documentation to find out the
possible values.
axis_center(float, float), optional
Tuple of two floats denoting the coordinates of the center or
{‘center’, ‘auto’}. Only available with MatplotlibBackend.
backendPlot, optional
A subclass of Plot, which will perform the rendering.
Default to MatplotlibBackend.
color_funccallable, optional
Define the line color mapping when use_cm=True. It can either be:
A numerical function supporting vectorization. The arity can be:
1 argument: f(t), where t is the parameter.
2 arguments: f(x,y) where x,y are the coordinates of
the points.
3 arguments: f(x,y,t).
A symbolic expression having at most as many free symbols as
expr_x or expr_y.
None: the default value (color mapping applied to the parameter).
force_real_evalboolean, optional
Default to False, with which the numerical evaluation is attempted
over a complex domain, which is slower but produces correct results.
Set this to True if performance is of paramount importance, but be
aware that it might produce wrong results. It only works with
adaptive=False.
labelstr or list/tuple, optional
The label to be shown in the legend or in the colorbar. If not
provided, the string representation of expr will be used. The number
of labels must be equal to the number of expressions.
loss_fncallable or None
The loss function to be used by the adaptive learner.
Possible values:
None (default): it will use the default_loss from the
adaptive module.
callable : Refer to [2] for more information. Specifically,
look at adaptive.learner.learner1D to find more loss functions.
nint, optional
Used when the adaptive=False. The function is uniformly sampled
at n number of points. Default value to 1000.
If the adaptive=True, this parameter will be ignored.
paramsdict
A dictionary mapping symbols to parameters. This keyword argument
enables the interactive-widgets plot, which doesn’t support the
adaptive algorithm (meaning it will use adaptive=False).
Learn more by reading the documentation of iplot.
rendering_kwdict or list of dicts, optional
A dictionary of keywords/values which is passed to the backend’s
function to customize the appearance of lines. Refer to the
plotting library (backend) manual for more informations.
If a list of dictionaries is provided, the number of dictionaries must
be equal to the number of expressions.
showbool, optional
The default value is set to True. Set show to False and
the function will not display the plot. The returned instance of
the Plot class can then be used to save or display the plot
by calling the save() and show() methods respectively.
size(float, float), optional
A tuple in the form (width, height) to specify the size of
the overall figure. The default value is set to None, meaning
the size will be set by the backend.
titlestr, optional
Title of the plot. It is set to the latex representation of
the expression, if the plot has only one expression.
tx, ty, tpcallable, optional
Apply a numerical function to the x-direction, y-direction and
parameter, respectively.
use_cmboolean, optional
If True, apply a color map to the parametric lines.
If False, solid colors will be used instead. Default to True.
use_latexboolean, optional
Turn on/off the rendering of latex labels. If the backend doesn’t
support latex, it will render the string representations instead.
xlabel, ylabelstr, optional
Labels for the x-axis or y-axis, respectively.
xscale, yscale‘linear’ or ‘log’, optional
Sets the scaling of the x-axis or y-axis, respectively.
Default to 'linear'.
xlim, ylim(float, float), optional
Denotes the x-axis limits or y-axis limits, respectively,
(min,max), visible in the chart.
A parametric plot with multiple expressions with the same range with solid
line colors:
>>> plot_parametric((2*cos(t),sin(t)),(cos(t),2*sin(t)),... (t,0,2*pi),use_cm=False)Plot object containing:[0]: parametric cartesian line: (2*cos(t), sin(t)) for t over (0.0, 6.283185307179586)[1]: parametric cartesian line: (cos(t), 2*sin(t)) for t over (0.0, 6.283185307179586)
A parametric plot with multiple expressions with different ranges,
custom labels, custom rendering options and a transformation function
applied to the discretized parameter to convert radians to degrees:
>>> importnumpyasnp>>> plot_parametric(... (3*cos(u),3*sin(u),(u,0,2*pi),"u [deg]",{"lw":3}),... (3*cos(2*v),5*sin(4*v),(v,0,pi),"v [deg]"),... aspect="equal",tp=np.rad2deg)Plot object containing:[0]: parametric cartesian line: (3*cos(u), 3*sin(u)) for u over (0.0, 6.283185307179586)[1]: parametric cartesian line: (3*cos(2*v), 5*sin(4*v)) for v over (0.0, 3.141592653589793)
Interactive-widget plot. Refer to the interactive sub-module documentation
to learn more about the params dictionary. This plot illustrates:
the use of prange (parametric plotting range).
the use of the params dictionary to specify sliders in
their basic form: (default, min, max).
fromsympyimport*fromspbimport*x,a,s,e=symbols("x a s, e")plot_parametric(cos(a*x),sin(x),prange(x,s*pi,e*pi),params={a:(0.5,0,2),s:(0,0,2),e:(2,0,2),},aspect="equal",use_latex=False,xlim=(-1.25,1.25),ylim=(-1.25,1.25))
NOTE: this is an experimental plotting function as it only draws lines
without fills. The resulting visualization might change when new features
will be implemented.
Typical usage examples are in the followings:
Plotting a single parametric curve with a range
plot_parametric(expr_x, expr_y, range_u, range_v)
Plotting multiple parametric curves with the same range
The expression representing x and y component, respectively, of
the parametric function. It can be a:
Symbolic expression representing the function of one variable
to be plotted.
Numerical function of one variable, supporting vectorization.
In this case the following keyword arguments are not supported:
params.
range_u, range_v(symbol, min, max)
A 3-tuple denoting the parameter symbols, start and stop. For
example, (u, 0, 5), (v, 0, 5). If the ranges are not specified,
then they default to (-10, 10).
However, if the arguments are specified as
(expr_x, expr_y, range_u, range_v), …, you must specify the
ranges for each expressions manually.
rendering_kwdict, optional
A dictionary of keywords/values which is passed to the backend’s
function to customize the appearance of lines. Refer to the
plotting library (backend) manual for more informations.
aspect(float, float) or str, optional
Set the aspect ratio of the plot. The value depends on the backend
being used. Read that backend’s documentation to find out the
possible values.
backendPlot, optional
A subclass of Plot, which will perform the rendering.
Default to MatplotlibBackend.
nint, optional
The functions are uniformly sampled at n number of points.
Default value to 1000.
n1, n2int, optional
Number of lines to create along each direction. Default to 10.
Note: the higher the number, the slower the rendering.
rkw_u, rkw_vdict
A dictionary of keywords/values which is passed to the backend’s
function to customize the appearance of lines along the u and v
directions, respectively. These overrides rendering_kw if provided.
Refer to the plotting library (backend) manual for more informations.
showbool, optional
The default value is set to True. Set show to False and
the function will not display the plot. The returned instance of
the Plot class can then be used to save or display the plot
by calling the save() and show() methods respectively.
size(float, float), optional
A tuple in the form (width, height) to specify the size of
the overall figure. The default value is set to None, meaning
the size will be set by the backend.
titlestr, optional
Title of the plot. It is set to the latex representation of
the expression, if the plot has only one expression.
use_latexboolean, optional
Turn on/off the rendering of latex labels. If the backend doesn’t
support latex, it will render the string representations instead.
xlabel, ylabelstr, optional
Label for the x-axis or y-axis, respectively.
xscale, yscale‘linear’ or ‘log’, optional
Sets the scaling of the x-axis or y-axis, respectively.
Default to 'linear'.
xlim, ylim(float, float), optional
Denotes the x-axis or y-axis limits, (min,max), visible in the
chart.
Note: it is important to specify at least the range_x, otherwise the
function might create a rotated plot.
Parameters:
args
exprExpr
Expression representing the function of two variables to be plotted.
The expression representing the function of two variables to be
plotted. It can be a:
Symbolic expression.
Numerical function of two variable, supporting vectorization.
In this case the following keyword arguments are not supported:
params.
range_x: (symbol, min, max)
A 3-tuple denoting the range of the x variable. Default values:
min=-10 and max=10.
range_y: (symbol, min, max)
A 3-tuple denoting the range of the y variable. Default values:
min=-10 and max=10.
labelstr, optional
The label to be shown in the colorbar. If not provided, the string
representation of expr will be used.
rendering_kwdict, optional
A dictionary of keywords/values which is passed to the backend’s
function to customize the appearance of surfaces. Refer to the
plotting library (backend) manual for more informations.
adaptivebool, optional
The default value is set to False, which uses a uniform sampling
strategy with number of discretization points n1 and n2 along
the x and y directions, respectively.
Set adaptive to True to use the adaptive algorithm implemented in
[3] to create smooth plots. Use adaptive_goal and loss_fn
to further customize the output.
adaptive_goalcallable, int, float or None
Controls the “smoothness” of the evaluation. Possible values:
None (default): it will use the following goal:
lambdal:l.loss()<0.01
number (int or float). The lower the number, the more
evaluation points. This number will be used in the following goal:
lambdal:l.loss()<number
callable: a function requiring one input element, the learner. It
must return a float number. Refer to [3] for more information.
backendPlot, optional
A subclass of Plot, which will perform the rendering.
Default to MatplotlibBackend.
color_funccallable, optional
Define the surface color mapping when use_cm=True.
It can either be:
A numerical function of 3 variables, x, y, z (the points computed
by the internal algorithm) supporting vectorization.
A symbolic expression having at most as many free symbols as
expr.
None: the default value (color mapping applied to the z-value of
the surface).
force_real_evalboolean, optional
Default to False, with which the numerical evaluation is attempted
over a complex domain, which is slower but produces correct results.
Set this to True if performance is of paramount importance, but be
aware that it might produce wrong results. It only works with
adaptive=False.
is_polarboolean, optional
Default to False. If True, requests a polar discretization. In this
case, range_x represents the radius, range_y represents the
angle.
labelstr or list/tuple, optional
The label to be shown in the colorbar. If not provided, the string
representation of expr will be used. The number of labels must be
equal to the number of expressions.
loss_fncallable or None
The loss function to be used by the adaptive learner.
Possible values:
None (default): it will use the default_loss from the
adaptive module.
callable : Refer to [3] for more information. Specifically,
look at adaptive.learner.learnerND to find more loss functions.
n1, n2int, optional
n1 and n2 set the number of discretization points along the
x and y ranges, respectively. Default value to 100.
nint or two-elements tuple (n1, n2), optional
If an integer is provided, the x and y ranges are sampled uniformly
at n of points. If a tuple is provided, it overrides
n1 and n2.
paramsdict
A dictionary mapping symbols to parameters. This keyword argument
enables the interactive-widgets plot, which doesn’t support the
adaptive algorithm (meaning it will use adaptive=False).
Learn more by reading the documentation of iplot.
rendering_kwdict or list of dicts, optional
A dictionary of keywords/values which is passed to the backend’s
function to customize the appearance of surfaces. Refer to the
plotting library (backend) manual for more informations.
If a list of dictionaries is provided, the number of dictionaries must
be equal to the number of expressions.
showbool, optional
The default value is set to True. Set show to False and
the function will not display the plot. The returned instance of
the Plot class can then be used to save or display the plot
by calling the save() and show() methods respectively.
size(float, float), optional
A tuple in the form (width, height) to specify the size of
the overall figure. The default value is set to None, meaning
the size will be set by the backend.
titlestr, optional
Title of the plot. It is set to the latex representation of
the expression, if the plot has only one expression.
tx, ty, tzcallable, optional
Apply a numerical function to the discretized domain in the
x, y and z direction, respectively.
use_cmboolean, optional
If True, apply a color map to the surface.
If False, solid colors will be used instead. Default to False.
use_latexboolean, optional
Turn on/off the rendering of latex labels. If the backend doesn’t
support latex, it will render the string representations instead.
wireframeboolean, optional
Enable or disable a wireframe over the surface. Depending on the number
of wireframe lines (see wf_n1 and wf_n2), activating this
option might add a considerable overhead during the plot’s creation.
Default to False (disabled).
wf_n1, wf_n2int, optional
Number of wireframe lines along the x and y ranges, respectively.
Default to 10. Note that increasing this number might considerably
slow down the plot’s creation.
wf_npointint or None, optional
Number of discretization points for the wireframe lines. Default to
None, meaning that each wireframe line will have n1 or n2
number of points, depending on the line direction.
wf_rendering_kwdict, optional
A dictionary of keywords/values which is passed to the backend’s
function to customize the appearance of wireframe lines.
xlabel, ylabel, zlabelstr, optional
Labels for the x-axis or y-axis or z-axis, respectively.
xlim, ylim(float, float), optional
Denotes the x-axis limits or y-axis limits, (min,max), visible in
the chart. Note that the function is still being evaluate over
range_x and range_y.
zlim(float, float), optional
Denotes the z-axis limits, (min,max), visible in the chart.
Note: for documentation purposes, the following examples uses Matplotlib.
However, Matplotlib’s 3D capabilities are rather limited. Consider running
these examples with a different backend (hence, modify the rendering_kw
and wf_rendering_kw to pass the correct options to the backend).
>>> plot3d(cos((x**2+y**2)),(x,-3,3),(y,-3,3))Plot object containing:[0]: cartesian surface: cos(x**2 + y**2) for x over (-3.0, 3.0) and y over (-3.0, 3.0)
Multiple plots with same range. Set use_cm=True to distinguish the
expressions:
>>> plot3d(x*y,-x*y,(x,-5,5),(y,-5,5),use_cm=True)Plot object containing:[0]: cartesian surface: x*y for x over (-5.0, 5.0) and y over (-5.0, 5.0)[1]: cartesian surface: -x*y for x over (-5.0, 5.0) and y over (-5.0, 5.0)
Multiple plots with different ranges and solid colors.
>>> f=x**2+y**2>>> plot3d((f,(x,-3,3),(y,-3,3)),... (-f,(x,-5,5),(y,-5,5)))Plot object containing:[0]: cartesian surface: x**2 + y**2 for x over (-3.0, 3.0) and y over (-3.0, 3.0)[1]: cartesian surface: -x**2 - y**2 for x over (-5.0, 5.0) and y over (-5.0, 5.0)
Single plot with a polar discretization, a color function mapping a
colormap to the radius. Note that the same result can be achieved with
plot3d_revolution.
Interactive-widget plot. Refer to the interactive sub-module documentation
to learn more about the params dictionary. This plot illustrates:
the use of prange (parametric plotting range).
the use of the params dictionary to specify sliders in
their basic form: (default, min, max).
fromsympyimport*fromspbimport*x,y,a,b,d=symbols("x y a b d")plot3d(cos(x**2+y**2)*exp(-(x**2+y**2)*d),prange(x,-2*a,2*a),prange(y,-2*b,2*b),params={a:(1,0,3),b:(1,0,3),d:(0.25,0,1),},backend=PB,use_cm=True,n=100,aspect=dict(x=1.5,y=1.5,z=0.75),wireframe=True,wf_n1=15,wf_n2=15,throttled=True,use_latex=False)
The expression representing x component of the parametric
function. It can be a:
Symbolic expression representing the function of one variable
to be plotted.
Numerical function of one variable, supporting vectorization.
In this case the following keyword arguments are not supported:
params.
expr_yExpr
The expression representing y component of the parametric
function. It can be a:
Symbolic expression representing the function of one variable
to be plotted.
Numerical function of one variable, supporting vectorization.
In this case the following keyword arguments are not supported:
params.
expr_zExpr
The expression representing z component of the parametric
function. It can be a:
Symbolic expression representing the function of one variable
to be plotted.
Numerical function of one variable, supporting vectorization.
In this case the following keyword arguments are not supported:
params.
range(symbol, min, max)
A 3-tuple denoting the range of the parameter variable.
labelstr, optional
An optional string denoting the label of the expression
to be visualized on the legend. If not provided, the string
representation of the expression will be used.
rendering_kwdict, optional
A dictionary of keywords/values which is passed to the backend’s
function to customize the appearance of lines. Refer to the
plotting library (backend) manual for more informations.
adaptivebool, optional
Setting adaptive=True activates the adaptive algorithm
implemented in [4] to create smooth plots. Use adaptive_goal
and loss_fn to further customize the output.
The default value is False, which uses an uniform sampling
strategy, where the number of discretization points is specified by
the n keyword argument.
adaptive_goalcallable, int, float or None
Controls the “smoothness” of the evaluation. Possible values:
None (default): it will use the following goal:
lambdal:l.loss()<0.01
number (int or float). The lower the number, the more
evaluation points. This number will be used in the following goal:
lambdal:l.loss()<number
callable: a function requiring one input element, the learner. It
must return a float number. Refer to [4] for more information.
backendPlot, optional
A subclass of Plot, which will perform the rendering.
Default to MatplotlibBackend.
color_funccallable, optional
Define the line color mapping when use_cm=True. It can either be:
A numerical function supporting vectorization. The arity can be:
1 argument: f(t), where t is the parameter.
3 arguments: f(x,y,z) where x,y,z are the coordinates
of the points.
4 arguments: f(x,y,z,t).
A symbolic expression having at most as many free symbols as
expr_x or expr_y or expr_z.
None: the default value (color mapping applied to the parameter).
force_real_evalboolean, optional
Default to False, with which the numerical evaluation is attempted
over a complex domain, which is slower but produces correct results.
Set this to True if performance is of paramount importance, but be
aware that it might produce wrong results. It only works with
adaptive=False.
is_pointboolean, optional
Default to False, which will render a line connecting all the points.
If True, a scatter plot will be generated.
labelstr or list/tuple, optional
The label to be shown in the legend or in the colorbar. If not
provided, the string representation of expr will be used.
The number of labels must be equal to the number of expressions.
loss_fncallable or None
The loss function to be used by the adaptive learner.
Possible values:
None (default): it will use the default_loss from the
adaptive module.
callable : Refer to [4] for more information. Specifically,
look at adaptive.learner.learner1D to find more loss functions.
nint, optional
Used when the adaptive=False. The function is uniformly
sampled at n number of points. Default value to 1000.
If the adaptive=True, this parameter will be ignored.
paramsdict
A dictionary mapping symbols to parameters. This keyword argument
enables the interactive-widgets plot, which doesn’t support the
adaptive algorithm (meaning it will use adaptive=False).
Learn more by reading the documentation of iplot.
rendering_kwdict or list of dicts, optional
A dictionary of keywords/values which is passed to the backend’s
function to customize the appearance of lines. Refer to the
plotting library (backend) manual for more informations.
If a list of dictionaries is provided, the number of dictionaries must
be equal to the number of expressions.
showbool, optional
The default value is set to True. Set show to False and
the function will not display the plot. The returned instance of
the Plot class can then be used to save or display the plot
by calling the save() and show() methods respectively.
size(float, float), optional
A tuple in the form (width, height) to specify the size of
the overall figure. The default value is set to None, meaning
the size will be set by the backend.
titlestr, optional
Title of the plot. It is set to the latex representation of
the expression, if the plot has only one expression.
tx, ty, tz, tpcallable, optional
Apply a numerical function to the x, y, z directions and to the
discretized parameter.
use_cmboolean, optional
If True, apply a color map to the parametric lines.
If False, solid colors will be used instead. Default to True.
use_latexboolean, optional
Turn on/off the rendering of latex labels. If the backend doesn’t
support latex, it will render the string representations instead.
xlabel, ylabel, zlabelstr, optional
Labels for the x-axis, y-axis, z-axis, respectively.
xlim, ylim, zlim(float, float), optional
Denotes the axis limits, (min, max), visible in the chart.
Note: for documentation purposes, the following examples uses Matplotlib.
However, Matplotlib’s 3D capabilities are rather limited. Consider running
these examples with a different backend (hence, modify rendering_kw
to pass the correct options to the backend).
>>> plot3d_parametric_line(cos(t),sin(t),t,(t,-5,5))Plot object containing:[0]: 3D parametric cartesian line: (cos(t), sin(t), t) for t over (-5.0, 5.0)
Plot multiple parametric 3D lines with different ranges:
>>> a,b,n=2,1,4>>> p,r,s=symbols("p r s")>>> xp=a*cos(p)*cos(n*p)>>> yp=a*sin(p)*cos(n*p)>>> zp=b*cos(n*p)**2+pi>>> xr=root(r,3)*cos(r)>>> yr=root(r,3)*sin(r)>>> zr=0>>> plot3d_parametric_line(... (xp,yp,zp,(p,0,piifn%2==1else2*pi),"petals"),... (xr,yr,zr,(r,0,6*pi),"roots"),... (-sin(s)/3,0,s,(s,0,pi),"stem"),use_cm=False)Plot object containing:[0]: 3D parametric cartesian line: (2*cos(p)*cos(4*p), 2*sin(p)*cos(4*p), cos(4*p)**2 + pi) for p over (0.0, 6.283185307179586)[1]: 3D parametric cartesian line: (r**(1/3)*cos(r), r**(1/3)*sin(r), 0) for r over (0.0, 18.84955592153876)[2]: 3D parametric cartesian line: (-sin(s)/3, 0, s) for s over (0.0, 3.141592653589793)
Interactive-widget plot of the parametric line over a tennis ball.
Refer to the interactive sub-module documentation to learn more about the
params dictionary. This plot illustrates:
combining together different plots.
the use of prange (parametric plotting range).
the use of the params dictionary to specify sliders in
their basic form: (default, min, max).
fromsympyimport*fromspbimport*importk3da,b,s,e,t=symbols("a, b, s, e, t")c=2*sqrt(a*b)r=a+bparams={a:(1.5,0,2),b:(1,0,2),s:(0,0,2),e:(2,0,2)}sphere=plot3d_revolution((r*cos(t),r*sin(t)),(t,0,pi),params=params,n=50,parallel_axis="x",backend=KB,show_curve=False,show=False,rendering_kw={"color":0x353535})line=plot3d_parametric_line(a*cos(t)+b*cos(3*t),a*sin(t)-b*sin(3*t),c*sin(2*t),prange(t,s*pi,e*pi),{"color_map":k3d.matplotlib_color_maps.Summer},params=params,backend=KB,show=False,use_latex=False)(line+sphere).show()
Expression representing the function along x. It can be a:
Symbolic expression.
Numerical function of two variable, f(u, v), supporting
vectorization. In this case the following keyword arguments are
not supported: params.
expr_y: Expr
Expression representing the function along y. It can be a:
Symbolic expression.
Numerical function of two variable, f(u, v), supporting
vectorization. In this case the following keyword arguments are
not supported: params.
expr_z: Expr
Expression representing the function along z. It can be a:
Symbolic expression.
Numerical function of two variable, f(u, v), supporting
vectorization. In this case the following keyword arguments are
not supported: params.
range_u: (symbol, min, max)
A 3-tuple denoting the range of the u variable.
range_v: (symbol, min, max)
A 3-tuple denoting the range of the v variable.
labelstr, optional
The label to be shown in the colorbar. If not provided, the string
representation of the expression will be used.
rendering_kwdict, optional
A dictionary of keywords/values which is passed to the backend’s
function to customize the appearance of surfaces. Refer to the
plotting library (backend) manual for more informations.
backendPlot, optional
A subclass of Plot, which will perform the rendering.
Default to MatplotlibBackend.
color_funccallable, optional
Define the surface color mapping when use_cm=True.
It can either be:
A numerical function supporting vectorization. The arity can be:
1 argument: f(u), where u is the first parameter.
2 arguments: f(u,v) where u,v are the parameters.
3 arguments: f(x,y,z) where x,y,z are the coordinates of
the points.
5 arguments: f(x,y,z,u,v).
A symbolic expression having at most as many free symbols as
expr_x or expr_y or expr_z.
None: the default value (color mapping applied to the z-value of
the surface).
force_real_evalboolean, optional
Default to False, with which the numerical evaluation is attempted
over a complex domain, which is slower but produces correct results.
Set this to True if performance is of paramount importance, but be
aware that it might produce wrong results. It only works with
adaptive=False.
labelstr or list/tuple, optional
The label to be shown in the colorbar. If not provided, the string
representation will be used. The number of labels must be
equal to the number of expressions.
n1, n2int, optional
n1 and n2 set the number of discretization points along the
u and v ranges, respectively. Default value to 100.
nint or two-elements tuple (n1, n2), optional
If an integer is provided, the u and v ranges are sampled uniformly
at n of points. If a tuple is provided, it overrides
n1 and n2.
paramsdict
A dictionary mapping symbols to parameters. This keyword argument
enables the interactive-widgets plot. Learn more by reading the
documentation of iplot.
rendering_kwdict or list of dicts, optional
A dictionary of keywords/values which is passed to the backend’s
function to customize the appearance of surfaces. Refer to the
plotting library (backend) manual for more informations.
If a list of dictionaries is provided, the number of dictionaries must
be equal to the number of expressions.
showbool, optional
The default value is set to True. Set show to False and
the function will not display the plot. The returned instance of
the Plot class can then be used to save or display the plot
by calling the save() and show() methods respectively.
size(float, float), optional
A tuple in the form (width, height) to specify the size of
the overall figure. The default value is set to None, meaning
the size will be set by the backend.
titlestr, optional
Title of the plot. It is set to the latex representation of
the expression, if the plot has only one expression.
tx, ty, tzcallable, optional
Apply a numerical function to the discretized domain in the
x, y and z direction, respectively.
use_cmboolean, optional
If True, apply a color map to the surface.
If False, solid colors will be used instead. Default to False.
use_latexboolean, optional
Turn on/off the rendering of latex labels. If the backend doesn’t
support latex, it will render the string representations instead.
wireframeboolean, optional
Enable or disable a wireframe over the surface. Depending on the number
of wireframe lines (see wf_n1 and wf_n2), activating this
option might add a considerable overhead during the plot’s creation.
Default to False (disabled).
wf_n1, wf_n2int, optional
Number of wireframe lines along the u and v ranges, respectively.
Default to 10. Note that increasing this number might considerably
slow down the plot’s creation.
wf_npointint or None, optional
Number of discretization points for the wireframe lines. Default to
None, meaning that each wireframe line will have n1 or n2
number of points, depending on the line direction.
wf_rendering_kwdict, optional
A dictionary of keywords/values which is passed to the backend’s
function to customize the appearance of wireframe lines.
xlabel, ylabel, zlabelstr, optional
Label for the x-axis or y-axis or z-axis, respectively.
xlim, ylim, zlim(float, float), optional
Denotes the x-axis limits, or y-axis limits, or z-axis limits,
respectively, (min,max), visible in the chart.
Note: for documentation purposes, the following examples uses Matplotlib.
However, Matplotlib’s 3D capabilities are rather limited. Consider running
these examples with a different backend (hence, modify the rendering_kw
and wf_rendering_kw to pass the correct options to the backend).
>>> plot3d_parametric_surface(... u*cos(v),u*sin(v),u*cos(4*v)/2,... (u,0,pi),(v,0,2*pi),... use_cm=False,title="Sinusoidal Cone")Plot object containing:[0]: parametric cartesian surface: (u*cos(v), u*sin(v), u*cos(4*v)/2) for u over (0.0, 3.141592653589793) and v over (0.0, 6.283185307179586)
Customize the appearance of the surface by changing the colormap. Apply a
color function mapping the v values. Activate the wireframe to better
visualize the parameterization.
Interactive-widget plot. Refer to the interactive sub-module documentation
to learn more about the params dictionary. This plot illustrates:
the use of prange (parametric plotting range).
the use of the params dictionary to specify sliders in
their basic form: (default, min, max).
fromsympyimport*fromspbimport*importk3dalpha,u,v,up,vp=symbols("alpha u v u_p v_p")plot3d_parametric_surface((exp(u)*cos(v-alpha)/2+exp(-u)*cos(v+alpha)/2,exp(u)*sin(v-alpha)/2+exp(-u)*sin(v+alpha)/2,cos(alpha)*u+sin(alpha)*v),prange(u,-up,up),prange(v,0,vp*pi),backend=KB,use_cm=True,color_func=lambdau,v:v,rendering_kw={"color_map":k3d.colormaps.paraview_color_maps.Hue_L60},wireframe=True,wf_n2=15,wf_rendering_kw={"width":0.005},grid=False,n=50,use_latex=False,params={alpha:(0,0,pi),up:(1,0,2),vp:(2,0,2),},title="Catenoid \, to \, Right \, Helicoid \, Transformation")
Interactive-widget plot. Refer to the interactive sub-module documentation
to learn more about the params dictionary. Note that the plot’s
creation might be slow due to the wireframe lines.
fromsympyimport*fromspbimport*importparamn,u,v=symbols("n, u, v")x=v*cos(u)y=v*sin(u)z=sin(n*u)plot3d_parametric_surface((x,y,z,(u,0,2*pi),(v,-1,0)),params={n:param.Integer(3,label="n")},backend=KB,use_cm=True,title=r"Plücker's \, conoid",wireframe=True,wf_rendering_kw={"width":0.004},wf_n1=75,wf_n2=6,imodule="panel")
Numerical function of two variable, f(theta, phi), supporting
vectorization. In this case the following keyword arguments are
not supported: params.
theta: (symbol, min, max)
A 3-tuple denoting the range of the polar angle, which is limited
in [0, pi]. Consider a sphere:
theta=0 indicates the north pole.
theta=pi/2 indicates the equator.
theta=pi indicates the south pole.
range_v: (symbol, min, max)
A 3-tuple denoting the range of the azimuthal angle, which is
limited in [0, 2*pi].
labelstr, optional
The label to be shown in the colorbar. If not provided, the string
representation of the expression will be used.
rendering_kwdict, optional
A dictionary of keywords/values which is passed to the backend’s
function to customize the appearance of surfaces. Refer to the
plotting library (backend) manual for more informations.
Keyword arguments are the same as ``plot3d_parametric_surface``. Refer to
Note: for documentation purposes, the following examples uses Matplotlib.
However, Matplotlib’s 3D capabilities are rather limited. Consider running
these examples with a different backend (hence, modify the rendering_kw
and wf_rendering_kw to pass the correct options to the backend).
>>> plot3d_spherical(1,(theta,0,0.7*pi),(phi,0,1.8*pi))Plot object containing:[0]: parametric cartesian surface: (sin(theta)*cos(phi), sin(phi)*sin(theta), cos(theta)) for theta over (0.0, 2.199114857512855) and phi over (0.0, 5.654866776461628)
Multiple surfaces with wireframe lines, using Plotly. Note that activating
the wireframe option might add a considerable overhead during the plot’s
creation.
Interactive-widget plot of real spherical harmonics, highlighting the
regions in which the real part is positive and negative.
Note that the plot’s creation and update might be slow and that
it must be m<n at all times.
Refer to the interactive sub-module documentation to learn more about the
params dictionary.
Generate a surface of revolution by rotating a curve around an axis of
rotation.
Parameters:
curveExpr, list/tuple of 2 or 3 elements
The curve to be revolved, which can be either:
a symbolic expression
a 2-tuple representing a parametric curve in 2D space
a 3-tuple representing a parametric curve in 3D space
range_t(symbol, min, max)
A 3-tuple denoting the range of the parameter of the curve.
range_phi(symbol, min, max)
A 3-tuple denoting the range of the azimuthal angle where the curve
will be revolved. Default to (phi,0,2*pi).
axis(coord1, coord2)
A 2-tuple that specifies the position of the rotation axis.
Depending on the value of parallel_axis:
"x": the rotation axis intersects the YZ plane at
(coord1, coord2).
"y": the rotation axis intersects the XZ plane at
(coord1, coord2).
"z": the rotation axis intersects the XY plane at
(coord1, coord2).
Default to (0,0).
parallel_axisstr
Specify the axis parallel to the axis of rotation. Must be one of the
following options: “x”, “y” or “z”. Default to “z”.
show_curvebool
Add the initial curve to the plot. Default to False.
curve_kwdict
A dictionary of options that will be passed to
plot3d_parametric_line if show_curve=True in order to customize
the appearance of the initial curve. Refer to its documentation for
more information.
**kwargs
Keyword arguments are the same as plot3d_parametric_surface.
Refer to its documentation for more information.
Note: for documentation purposes, the following examples uses Matplotlib.
However, Matplotlib’s 3D capabilities are rather limited. Consider running
these examples with a different backend (hence, modify the curve_kw,
rendering_kw and wf_rendering_kw to pass the correct options to
the backend).
>>> plot3d_revolution(... cos(t),(t,0,pi),... # use a color map on the surface to indicate the azimuthal angle... use_cm=True,color_func=lambdat,phi:phi,... rendering_kw={"alpha":0.6,"cmap":"twilight"},... # indicates the azimuthal angle on the colorbar label... label=r"$\phi$ [rad]",... show_curve=True,... # this dictionary will be passes to plot3d_parametric_line in... # order to draw the initial curve... curve_kw=dict(rendering_kw={"color":"r","label":"cos(t)"}),... # activate the wireframe to visualize the parameterization... wireframe=True,wf_n1=15,wf_n2=15,... wf_rendering_kw={"lw":0.5,"alpha":0.75})
Interactive-widget plot of a goblet. Refer to the interactive sub-module
documentation to learn more about the params dictionary.
This plot illustrates:
the use of prange (parametric plotting range).
the use of the params dictionary to specify sliders in
their basic form: (default, min, max).
fromsympyimport*fromspbimport*t,phi,u,v,w=symbols("t phi u v w")plot3d_revolution((t,cos(u*t),t**2),prange(t,0,v),prange(phi,0,w*pi),axis=(1,0.2),params={u:(2.5,0,6),v:(2,0,3),w:(2,0,2)},n=50,backend=KB,force_real_eval=True,wireframe=True,wf_n1=15,wf_n2=15,wf_rendering_kw={"width":0.004},show_curve=True,curve_kw={"rendering_kw":{"width":0.025}},use_latex=False)
it is important to specify the ranges, as they will determine the
orientation of the surface.
the number of discretization points is crucial as the algorithm will
discretize a volume. A high number of discretization points creates a
smoother mesh, at the cost of a much higher memory consumption and
slower computation.
To plot f(x,y,z)=c either write expr=f(x,y,z)-c or
pass the appropriate keyword to rendering_kw. Read the backends
documentation to find out the available options.
Only PlotlyBackend and K3DBackend support 3D implicit plotting.
Parameters:
args
expr: Expr
Implicit expression. It can be a:
Symbolic expression.
Numerical function of three variable, f(x, y, z), supporting
vectorization.
range_x: (symbol, min, max)
A 3-tuple denoting the range of the x variable.
range_y: (symbol, min, max)
A 3-tuple denoting the range of the y variable.
range_z: (symbol, min, max)
A 3-tuple denoting the range of the z variable.
rendering_kwdict, optional
A dictionary of keywords/values which is passed to the backend’s
function to customize the appearance of surfaces. Refer to the
plotting library (backend) manual for more informations.
backendPlot, optional
A subclass of Plot, which will perform the rendering.
n1, n2, n3int, optional
Set the number of discretization points along the x, y and z ranges,
respectively. Default value is 60.
nint or three-elements tuple (n1, n2, n3), optional
If an integer is provided, the x, y and z ranges are sampled uniformly
at n of points. If a tuple is provided, it overrides n1,
n2 and n3.
rendering_kwdict or list of dicts, optional
A dictionary of keywords/values which is passed to the backend’s
function to customize the appearance of surfaces. Refer to the
plotting library (backend) manual for more informations.
If a list of dictionaries is provided, the number of dictionaries must
be equal to the number of expressions.
showbool, optional
The default value is set to True. Set show to False and
the function will not display the plot. The returned instance of
the Plot class can then be used to save or display the plot
by calling the save() and show() methods respectively.
size(float, float), optional
A tuple in the form (width, height) to specify the size of
the overall figure. The default value is set to None, meaning
the size will be set by the backend.
titlestr, optional
Title of the plot. It is set to the latex representation of
the expression, if the plot has only one expression.
use_latexboolean, optional
Turn on/off the rendering of latex labels. If the backend doesn’t
support latex, it will render the string representations instead.
xlabel, ylabel, zlabelstr, optional
Labels for the x-axis, y-axis or z-axis, respectively.
xlim, ylim, zlim(float, float), optional
Denotes the x-axis limits, y-axis limits or z-axis limits,
respectively, (min,max), visible in the chart. Note that the
function is still being evaluated over the range_x, range_y
and range_z.
>>> plot_contour(cos((x**2+y**2))*exp(-(x**2+y**2)/10),... (x,-5,5),(y,-5,5))Plot object containing:[0]: contour: exp(-x**2/10 - y**2/10)*cos(x**2 + y**2) for x over (-5.0, 5.0) and y over (-5.0, 5.0)
>>> expr=5*(cos(x)-0.2*sin(y))**2+5*(-0.2*cos(x)+sin(y))**2>>> plot_contour(expr,(x,0,2*pi),(y,0,2*pi),is_filled=False)Plot object containing:[0]: contour: 5*(-0.2*sin(y) + cos(x))**2 + 5*(sin(y) - 0.2*cos(x))**2 for x over (0.0, 6.283185307179586) and y over (0.0, 6.283185307179586)
Visually inspect the solutions of a system of 2 non-linear equations.
The intersections between the contour lines represent the solutions.
>>> eq1=Eq((cos(x)-sin(y)/2)**2+3*(-sin(x)+cos(y)/2)**2,2)>>> eq2=Eq((cos(x)-2*sin(y))**2-(sin(x)+2*cos(y))**2,3)>>> plot_contour(eq1.rewrite(Add),eq2.rewrite(Add),{"levels":[0]},... (x,0,2*pi),(y,0,2*pi),is_filled=False,clabels=False)Plot object containing:[0]: contour: 3*(-sin(x) + cos(y)/2)**2 + (-sin(y)/2 + cos(x))**2 - 2 for x over (0.0, 6.283185307179586) and y over (0.0, 6.283185307179586)[1]: contour: -(sin(x) + 2*cos(y))**2 + (-2*sin(y) + cos(x))**2 - 3 for x over (0.0, 6.283185307179586) and y over (0.0, 6.283185307179586)
>>> r,theta=symbols("r, theta")>>> plot_contour(sin(2*r)*cos(theta),(theta,0,2*pi),(r,0,7),... {"levels":100},polar_axis=True,aspect="equal")Plot object containing:[0]: contour: sin(2*r)*cos(theta) for theta over (0.0, 6.283185307179586) and r over (0.0, 7.0)
Interactive-widget plot. Refer to the interactive sub-module documentation
to learn more about the params dictionary. This plot illustrates:
the use of prange (parametric plotting range).
the use of the params dictionary to specify sliders in
their basic form: (default, min, max).
fromsympyimport*fromspbimport*x,y,a,b,xp,yp=symbols("x y a b x_p y_p")expr=(cos(x)+a*sin(x)*sin(y)-b*sin(x)*cos(y))**2plot_contour(expr,prange(x,0,xp*pi),prange(y,0,yp*pi),params={a:(1,0,2),b:(1,0,2),xp:(1,0,2),yp:(2,0,2)},grid=False,use_latex=False)
plot_implicit, by default, generates a contour using a mesh grid of fixed
number of points. The greater the number of points, the greater the memory
used. By setting adaptive=True, interval arithmetic will be used to
plot functions. If the expression cannot be plotted using interval
arithmetic, it defaults to generating a contour using a mesh grid.
With interval arithmetic, the line width can become very small; in those
cases, it is better to use the mesh grid approach.
Parameters:
args
exprExpr, Relational, BooleanFunction
The equation / inequality that is to be plotted.
rangestuples or Symbol
Two tuple denoting the discretization domain, for example:
(x,-10,10),(y,-10,10)
To get a correct plot, at least the horizontal range must be
provided. If no range is given, then the free symbols in the
expression will be assigned in the order they are sorted, which
could ‘invert’ the axis.
Alternatively, a single Symbol corresponding to the horizontal
axis must be provided, which will be internally converted to a
range (sym,-10,10).
labelstr, optional
The label to be shown when multiple expressions are plotted.
If not provided, the string representation of the expression
will be used.
rendering_kwdict, optional
A dictionary of keywords/values which is passed to the backend’s
function to customize the appearance of contours. Refer to the
plotting library (backend) manual for more informations.
adaptivebool, optional
The default value is set to False, meaning that the internal
algorithm uses a mesh grid approach. In such case, Boolean
combinations of expressions cannot be plotted.
If set to True, the internal algorithm uses interval arithmetic.
It switches to the meshgrid approach if the expression cannot be
plotted using interval arithmetic.
aspect(float, float) or str, optional
Set the aspect ratio of the plot. The value depends on the backend
being used. Read that backend’s documentation to find out the
possible values.
backendPlot, optional
A subclass of Plot, which will perform the rendering.
Default to MatplotlibBackend.
depthinteger
The depth of recursion for adaptive mesh grid. Default value is 0.
Takes value in the range (0, 4).
Think of the resulting plot as a picture composed by pixels. By
increasing depth we are increasing the number of pixels, thus
obtaining a more accurate plot.
labelstr or list/tuple, optional
The label to be shown in the legend. If not provided, the string
representation of expr will be used. The number of labels must be
equal to the number of expressions.
rendering_kwdict or list of dicts, optional
A dictionary of keywords/values which is passed to the backend’s
function to customize the appearance. Refer to the plotting library
(backend) manual for more informations.
If a list of dictionaries is provided, the number of dictionaries must
be equal to the number of expressions.
n1, n2int
Number of discretization points in the horizontal and vertical
directions when adaptive=False. Default to 1000.
nint or two-elements tuple (n1, n2), optional
If an integer is provided, the x and y ranges are sampled uniformly
at n of points. If a tuple is provided, it overrides
n1 and n2.
paramsdict
A dictionary mapping symbols to parameters. This keyword argument
enables the interactive-widgets plot. Learn more by reading the
documentation of iplot.
showBoolean
Default value is True. If set to False, the plot will not be shown.
See Plot for further information.
titlestring
The title for the plot.
use_latexboolean, optional
Turn on/off the rendering of latex labels. If the backend doesn’t
support latex, it will render the string representations instead.
xlabel, ylabelstring
The labels for the x-axis or y-axis, respectively.
Specify both ranges and set the number of discretization points:
>>> plot_implicit(... (x**2+y**2-1)**3-x**2*y**3,... (x,-1.5,1.5),(y,-1.5,1.5),... n=500)Plot object containing:[0]: Implicit expression: Eq(-x**2*y**3 + (x**2 + y**2 - 1)**3, 0) for x over (-1.5, 1.5) and y over (-1.5, 1.5)
Boolean expressions will be plotted with the adaptive algorithm. Note the
thin width of lines:
>>> plot_implicit(... Eq(y,sin(x))&(y>0),... Eq(y,sin(x))&(y<0),... (x,-2*pi,2*pi),(y,-4,4))Plot object containing:[0]: Implicit expression: (y > 0) & Eq(y, sin(x)) for x over (-6.283185307179586, 6.283185307179586) and y over (-4.0, 4.0)[1]: Implicit expression: (y < 0) & Eq(y, sin(x)) for x over (-6.283185307179586, 6.283185307179586) and y over (-4.0, 4.0)
Comparison of similar expressions plotted with different algorithms. Note:
Adaptive algorithm (adaptive=True) can be used with any expression,
but it usually creates lines with variable thickness. The depth
keyword argument can be used to improve the accuracy, but reduces line
thickness even further.
Mesh grid algorithm (adaptive=False) creates lines with contant
thickness.
Plotting multiple implicit expressions and setting labels:
>>> V,t,b,L=symbols("V, t, b, L")>>> L_array=[5,10,15,20,25]>>> b_val=0.0032>>> expr=b*V*0.277*t-b*L-log(1+b*V*0.277*t)>>> expr_list=[expr.subs({b:b_val,L:L_val})forL_valinL_array]>>> labels=["L = %s"%L_valforL_valinL_array]>>> plot_implicit(*expr_list,(t,0,3),(V,0,1000),label=labels)Plot object containing:[0]: Implicit expression: Eq(0.0008864*V*t - log(0.0008864*V*t + 1) - 0.016, 0) for t over (0.0, 3.0) and V over (0.0, 1000.0)[1]: Implicit expression: Eq(0.0008864*V*t - log(0.0008864*V*t + 1) - 0.032, 0) for t over (0.0, 3.0) and V over (0.0, 1000.0)[2]: Implicit expression: Eq(0.0008864*V*t - log(0.0008864*V*t + 1) - 0.048, 0) for t over (0.0, 3.0) and V over (0.0, 1000.0)[3]: Implicit expression: Eq(0.0008864*V*t - log(0.0008864*V*t + 1) - 0.064, 0) for t over (0.0, 3.0) and V over (0.0, 1000.0)[4]: Implicit expression: Eq(0.0008864*V*t - log(0.0008864*V*t + 1) - 0.08, 0) for t over (0.0, 3.0) and V over (0.0, 1000.0)
Interactive-widget implicit plot. Refer to the interactive sub-module
documentation to learn more about the params dictionary.
This plot illustrates:
the use of prange (parametric plotting range).
the use of the params dictionary to specify sliders in
their basic form: (default, min, max).
fromsympyimport*fromspbimport*x,y,a,b,c,d,e=symbols("x, y, a, b, c, d, e")expr=Eq(a*x**2-b*x+c,d*y+y**2)plot_implicit(expr,(x,-2,2),prange(y,-e,e),params={a:(10,-15,15),b:(7,-15,15),c:(3,-15,15),d:(2,-15,15),e:(10,1,15),},n=400,use_latex=False)
Interactive-widget plot of Guilloché Pattern. Refer to the interactive
sub-module documentation to learn more about the params dictionary.
This plot illustrates:
the use of prange (parametric plotting range).
the use of the params dictionary to specify the widgets to be
created by Holoviz’s Panel.
The name of the geometry entity to be eventually shown on the
legend. If not provided, the string representation of geom
will be used.
rendering_kwdict, optional
A dictionary of keywords/values which is passed to the backend’s
function to customize the appearance of lines or fills. Refer to
the plotting library (backend) manual for more informations.
aspect(float, float) or str, optional
Set the aspect ratio of the plot. The value depends on the backend
being used. Read that backend’s documentation to find out the
possible values.
backendPlot, optional
A subclass of Plot, which will perform the rendering.
Default to MatplotlibBackend.
is_filledboolean
Default to True. Fill the polygon/circle/ellipse.
labelstr or list/tuple, optional
The label to be shown in the legend. If not provided, the string
representation of geom will be used. The number of labels must be
equal to the number of geometric entities.
paramsdict
A dictionary in which the keys are symbols, enabling two different
modes of operation:
If the values are numbers, the dictionary acts like a substitution
dictionary for the provided geometric entities.
If the values are tuples representing parameters, the dictionary
enables the interactive-widgets plot, which doesn’t support the
adaptive algorithm (meaning it will use adaptive=False).
Learn more by reading the documentation of iplot.
axis_center(float, float), optional
Tuple of two floats denoting the coordinates of the center or
{‘center’, ‘auto’}. Only available with MatplotlibBackend.
rendering_kwdict or list of dicts, optional
A dictionary of keywords/values which is passed to the backend’s
functions to customize the appearance of lines and/or fills. Refer to
the plotting library (backend) manual for more informations.
If a list of dictionaries is provided, the number of dictionaries must
be equal to the number of expressions.
showbool, optional
The default value is set to True. Set show to False and
the function will not display the plot. The returned instance of
the Plot class can then be used to save or display the plot
by calling the save() and show() methods respectively.
size(float, float), optional
A tuple in the form (width, height) to specify the size of
the overall figure. The default value is set to None, meaning
the size will be set by the backend.
titlestr, optional
Title of the plot. It is set to the latex representation of
the expression, if the plot has only one expression.
use_latexboolean, optional
Turn on/off the rendering of latex labels. If the backend doesn’t
support latex, it will render the string representations instead.
xlabel, ylabel, zlabelstr, optional
Labels for the x-axis, y-axis or z-axis, respectively.
xlim, ylim, zlim(float, float), optional
Denotes the x-axis limits, y-axis limits or z-axis limits,
respectively, (min,max), visible in the chart.
Plot several numeric geometric entitiesy. By default, circles, ellipses and
polygons are going to be filled. Plotting Curve objects is the same as
plot_parametric.
Plot several symbolic geometric entities. We need to pass in the params
dictionary, which will be used to substitute symbols before numerical
evaluation. Note: here we also set custom labels:
A dictionary of keywords/values which is passed to the backend’s
function to customize the appearance of lines. Refer to the
plotting library (backend) manual for more informations.
aspect(float, float) or str, optional
Set the aspect ratio of the plot. The value depends on the backend
being used. Read that backend’s documentation to find out the
possible values.
axis_center(float, float), optional
Tuple of two floats denoting the coordinates of the center or
{‘center’, ‘auto’}. Only available with MatplotlibBackend.
backendPlot, optional
A subclass of Plot, which will perform the rendering.
Default to MatplotlibBackend.
is_pointboolean, optional
Default to False, which will render a line connecting all the points.
If True, a scatter plot will be generated.
is_filledboolean, optional
Default to False, which will render empty circular markers. It only
works if is_point=True.
If True, filled circular markers will be rendered.
labelstr or list/tuple, optional
The label to be shown in the legend. The number of labels must be
equal to the number of expressions.
paramsdict
A dictionary mapping symbols to parameters. This keyword argument
enables the interactive-widgets plot. Learn more by reading the
documentation of iplot.
rendering_kwdict or list of dicts, optional
A dictionary of keywords/values which is passed to the backend’s
function to customize the appearance of lines. Refer to the
plotting library (backend) manual for more informations.
If a list of dictionaries is provided, the number of dictionaries must
be equal to the number of expressions.
showbool, optional
The default value is set to True. Set show to False and
the function will not display the plot. The returned instance of
the Plot class can then be used to save or display the plot
by calling the save() and show() methods respectively.
size(float, float), optional
A tuple in the form (width, height) to specify the size of
the overall figure. The default value is set to None, meaning
the size will be set by the backend.
titlestr, optional
Title of the plot. It is set to the latex representation of
the expression, if the plot has only one expression.
use_latexboolean, optional
Turn on/off the rendering of latex labels. If the backend doesn’t
support latex, it will render the string representations instead.
xlabel, ylabelstr, optional
Labels for the x-axis or y-axis, respectively.
xscale, yscale‘linear’ or ‘log’, optional
Sets the scaling of the x-axis or y-axis, respectively.
Default to 'linear'.
xlim, ylim(float, float), optional
Denotes the x-axis limits or y-axis limits, respectively,
(min,max), visible in the chart.
>>> plot_list(([0],[0],"A"),([1],[1],"B"),([2],[0],"C"),... is_point=True,is_filled=True)Plot object containing:[0]: 2D list plot[1]: 2D list plot[2]: 2D list plot
A dictionary of keywords/values which is passed to the backend’s
function to customize the appearance of lines. Refer to the
plotting library (backend) manual for more informations.
backendPlot, optional
A subclass of Plot, which will perform the rendering.
Default to MatplotlibBackend.
color_funccallable, optional
A numerical function of 3 variables, x, y, z defining the line color.
Default to None. Requires use_cm=True in order to be applied.
is_pointboolean, optional
Default to False, which will render a line connecting all the points.
If True, a scatter plot will be generated.
is_filledboolean, optional
Default to True, which will render filled circular markers. It only
works if is_point=True. If True, filled circular markers will be
rendered. Note that some backend might not support this feature.
labelstr or list/tuple, optional
The label to be shown in the legend. The number of labels must be
equal to the number of expressions.
paramsdict
A dictionary mapping symbols to parameters. This keyword argument
enables the interactive-widgets plot. Learn more by reading the
documentation of iplot.
rendering_kwdict or list of dicts, optional
A dictionary of keywords/values which is passed to the backend’s
function to customize the appearance of lines. Refer to the
plotting library (backend) manual for more informations.
If a list of dictionaries is provided, the number of dictionaries must
be equal to the number of expressions.
showbool, optional
The default value is set to True. Set show to False and
the function will not display the plot. The returned instance of
the Plot class can then be used to save or display the plot
by calling the save() and show() methods respectively.
size(float, float), optional
A tuple in the form (width, height) to specify the size of
the overall figure. The default value is set to None, meaning
the size will be set by the backend.
titlestr, optional
Title of the plot. It is set to the latex representation of
the expression, if the plot has only one expression.
use_cmboolean, optional
If True, apply a color map to the parametric lines.
If False, solid colors will be used instead. Default to True.
use_latexboolean, optional
Turn on/off the rendering of latex labels. If the backend doesn’t
support latex, it will render the string representations instead.
xlabel, ylabel, zlabelstr, optional
Label for the x-axis, y-axis, z-axis, respectively.
xlim, ylim, zlim(float, float), optional
Denotes the x-axis limits, y-axis limits or z-axis limits,
respectively, (min,max), visible in the chart.
Expression representing the function of one variable to be
plotted.
range: (symbol, min, max)
A 3-tuple denoting the range of the x variable. Default values:
min=-10 and max=10.
labelstr, optional
The label to be shown in the legend. If not provided, the string
representation of expr will be used.
rendering_kwdict, optional
A dictionary of keywords/values which is passed to the backend’s
function to customize the appearance of lines. Refer to the
plotting library (backend) manual for more informations.
adaptivebool, optional
Setting adaptive=True activates the adaptive algorithm
implemented in [5] to create smooth plots. Use adaptive_goal
and loss_fn to further customize the output.
The default value is False, which uses an uniform sampling
strategy, where the number of discretization points is specified by
the n keyword argument.
adaptive_goalcallable, int, float or None
Controls the “smoothness” of the evaluation. Possible values:
None (default): it will use the following goal:
lambdal:l.loss()<0.01
number (int or float). The lower the number, the more
evaluation points. This number will be used in the following goal:
lambdal:l.loss()<number
callable: a function requiring one input element, the learner. It
must return a float number. Refer to [5] for more information.
aspect(float, float) or str, optional
Set the aspect ratio of the plot. The value depends on the backend
being used. Read that backend’s documentation to find out the
possible values.
axis_center(float, float), optional
Tuple of two floats denoting the coordinates of the center or
{‘center’, ‘auto’}. Only available with MatplotlibBackend.
backendPlot, optional
A subclass of Plot, which will perform the rendering.
Default to MatplotlibBackend.
detect_polesboolean, optional
Chose whether to detect and correctly plot poles.
Defaulto to False. To improve detection, increase the number of
discretization points n and/or change the value of eps.
dotsboolean
Wheter to show circular markers at the endpoints. Default to True.
epsfloat, optional
An arbitrary small value used by the detect_poles algorithm.
Default value to 0.1. Before changing this value, it is recommended to
increase the number of discretization points.
force_real_evalboolean, optional
Default to False, with which the numerical evaluation is attempted
over a complex domain, which is slower but produces correct results.
Set this to True if performance is of paramount importance, but be
aware that it might produce wrong results. It only works with
adaptive=False.
labelstr or list/tuple, optional
The label to be shown in the legend. If not provided, the string
representation of expr will be used. If a list/tuple is provided, the
number of labels must be equal to the number of expressions.
loss_fncallable or None
The loss function to be used by the adaptive learner.
Possible values:
None (default): it will use the default_loss from the
adaptive module.
callable : Refer to [5] for more information. Specifically,
look at adaptive.learner.learner1D to find more loss functions.
nint, optional
Used when the adaptive=False. The function is uniformly
sampled at n number of points. Default value to 1000.
If the adaptive=True, this parameter will be ignored.
showbool, optional
The default value is set to True. Set show to False and
the function will not display the plot. The returned instance of
the Plot class can then be used to save or display the plot
by calling the save() and show() methods respectively.
size(float, float), optional
A tuple in the form (width, height) to specify the size of
the overall figure. The default value is set to None, meaning
the size will be set by the backend.
titlestr, optional
Title of the plot. It is set to the latex representation of
the expression, if the plot has only one expression.
tx, tycallable, optional
Apply a numerical function to the discretized domain in the
x and y directions, respectively.
use_latexboolean, optional
Turn on/off the rendering of latex labels. If the backend doesn’t
support latex, it will render the string representations instead.
xlabel, ylabelstr, optional
Labels for the x-axis or y-axis, respectively.
xscale, yscale‘linear’ or ‘log’, optional
Sets the scaling of the x-axis or y-axis, respectively.
Default to ‘linear’.
xlim(float, float), optional
Denotes the x-axis limits, (min,max), visible in the chart.
Note that the function is still being evaluated over the specified
range.
ylim(float, float), optional
Denotes the y-axis limits, (min,max), visible in the chart.
>>> f=Piecewise((x**2,x<2),(5,Eq(x,2)),(10-x,True))>>> plot_piecewise(f,(x,-2,5))Plot object containing:[0]: cartesian line: x**2 for x over (-2.0, 1.999999)[1]: 2D list plot[2]: cartesian line: 10 - x for x over (2.000001, 5.0)[3]: 2D list plot[4]: 2D list plot
>>> plot_piecewise(Heaviside(x,0).rewrite(Piecewise),... (x,-10,10),dots=False)Plot object containing:[0]: cartesian line: 0 for x over (-10.0, 0.0)[1]: cartesian line: 1 for x over (1e-06, 10.0)
Plot multiple expressions in which the second piecewise expression has
a dotted line style.
>>> plot_piecewise(... (Heaviside(x,0).rewrite(Piecewise),(x,-10,10)),... (Piecewise(... (sin(x),x<-5),... (cos(x),x>5),... (1/x,True)),(x,-8,8),{"linestyle":":"}),... ylim=(-2,2),detect_poles=True)Plot object containing:[0]: cartesian line: 0 for x over (-10.0, 0.0)[1]: cartesian line: 1 for x over (1e-06, 10.0)[2]: 2D list plot[3]: 2D list plot[4]: cartesian line: sin(x) for x over (-8.0, -5.000001)[5]: 2D list plot[6]: cartesian line: cos(x) for x over (5.000001, 8.0)[7]: 2D list plot[8]: cartesian line: 1/x for x over (-5.0, 5.0)[9]: 2D list plot[10]: 2D list plot