Plotting fields

class sage.plot.plot_field.PlotField(xpos_array, ypos_array, xvec_array, yvec_array, options)

Primitive class that initializes the PlotField graphics type

__init__(xpos_array, ypos_array, xvec_array, yvec_array, options)

Create the graphics primitive PlotField. This sets options and the array to be plotted as attributes.

EXAMPLES:

sage: x,y = var('x,y')
sage: R=plot_slope_field(x+y,(x,0,1),(y,0,1),plot_points=2)
sage: r=R[0]
sage: r.options()['headlength']
0
sage: r.xpos_array
[0.0, 0.0, 1.0, 1.0]
sage: r.yvec_array
masked_array(data = [0.0 0.707106781187 0.707106781187 0.894427191],
             mask = [False False False False],
       fill_value = 1e+20)

TESTS:

We test dumping and loading a plot:

sage: x,y = var('x,y')
sage: P = plot_vector_field((sin(x), cos(y)), (x,-3,3), (y,-3,3))
sage: Q = loads(dumps(P))
_allowed_options()

Returns a dictionary with allowed options for PlotField.

EXAMPLES:

sage: x,y = var('x,y')
sage: P=plot_vector_field((sin(x), cos(y)), (x,-3,3), (y,-3,3))
sage: d=P[0]._allowed_options()
sage: d['pivot']
'Where the arrow should be placed in relation to the point (tail, middle, tip)'
_render_on_subplot(subplot)

TESTS:

sage: x,y = var('x,y')
sage: P=plot_vector_field((sin(x), cos(y)), (x,-3,3), (y,-3,3))
_repr_()

String representation of PlotField graphics primitive.

EXAMPLES:

sage: x,y = var('x,y')
sage: P=plot_vector_field((sin(x), cos(y)), (x,-3,3), (y,-3,3))
sage: P[0]
PlotField defined by a 20 x 20 vector grid
get_minmax_data()

Returns a dictionary with the bounding box data.

EXAMPLES:

sage: x,y = var('x,y')
sage: d = plot_vector_field((.01*x,x+y), (x,10,20), (y,10,20))[0].get_minmax_data()
sage: d['xmin']
10.0
sage: d['ymin']
10.0
sage.plot.plot_field.plot_slope_field(f, xrange, yrange, **kwds)

plot_slope_field takes a function of two variables xvar and yvar (for instance, if the variables are x and y, take f(x,y)), and at representative points (x_i,y_i) between xmin, xmax, and ymin, ymax respectively, plots a line with slope f(x_i,y_i) (see below).

plot_slope_field(f, (xvar, xmin, xmax), (yvar, ymin, ymax))

EXAMPLES:

A logistic function modeling population growth:

sage: x,y = var('x y')
sage: capacity = 3 # thousand
sage: growth_rate = 0.7 # population increases by 70% per unit of time
sage: plot_slope_field(growth_rate*(1-y/capacity)*y, (x,0,5), (y,0,capacity*2)).show(aspect_ratio=1)

Plot a slope field involving sin and cos:

sage: x,y = var('x y')
sage: plot_slope_field(sin(x+y)+cos(x+y), (x,-3,3), (y,-3,3)).show(aspect_ratio=1)
sage.plot.plot_field.plot_vector_field(*args, **kwds)

plot_vector_field takes two functions of two variables xvar and yvar (for instance, if the variables are x and y, take (f(x,y), g(x,y))) and plots vector arrows of the function over the specified ranges, with xrange being of xvar between xmin and xmax, and yrange similarly (see below).

plot_vector_field((f, g), (xvar, xmin, xmax), (yvar, ymin, ymax))

EXAMPLES:

Plot some vector fields involving sin and cos:

sage: x,y = var('x y')
sage: plot_vector_field((sin(x), cos(y)), (x,-3,3), (y,-3,3))
sage: plot_vector_field(( y, (cos(x)-2)*sin(x)), (x,-pi,pi), (y,-pi,pi))

Plot a gradient field:

sage: u,v = var('u v')
sage: f = exp(-(u^2+v^2))
sage: plot_vector_field(f.gradient(), (u,-2,2), (v,-2,2))

We ignore function values that are infinite or NaN:

sage: x,y = var('x,y')
sage: plot_vector_field( (-x/sqrt(x^2+y^2), -y/sqrt(x^2+y^2)), (x, -10, 10), (y, -10, 10))
sage: plot_vector_field( (-x/sqrt(x+y), -y/sqrt(x+y)), (x, -10, 10), (y, -10, 10))

Extra options will get passed on to show(), as long as they are valid:

sage: plot_vector_field((x, y), (x, -2, 2), (y, -2, 2), xmax=10)
sage: plot_vector_field((x, y), (x, -2, 2), (y, -2, 2)).show(xmax=10) # These are equivalent

Previous topic

Matrix Plots

Next topic

Points

This Page