List plots¶
- sage.plot.plot3d.list_plot3d.list_plot3d(v, interpolation_type='default', point_list=None, **kwds)[source]¶
- A 3-dimensional plot of a surface defined by the list \(v\) of points in 3-dimensional space. - INPUT: - v– something that defines a set of points in 3 space:- a matrix 
- a list of 3-tuples 
- a list of lists (all of the same length) – this is treated the same as a matrix 
 
 - OPTIONAL KEYWORDS: - interpolation_type– ‘linear’, ‘clough’ (CloughTocher2D), ‘spline’- ‘linear’ will perform linear interpolation - The option ‘clough’ will interpolate by using a piecewise cubic interpolating Bezier polynomial on each triangle, using a Clough-Tocher scheme. The interpolant is guaranteed to be continuously differentiable. The gradients of the interpolant are chosen so that the curvature of the interpolating surface is approximately minimized. - The option ‘spline’ interpolates using a bivariate B-spline. - When v is a matrix the default is to use linear interpolation, when v is a list of points the default is ‘clough’. 
- degree– integer between 1 and 5, controls the degree of spline used for spline interpolation. For data that is highly oscillatory use higher values
- point_list– if- point_list=Trueis passed, then if the array is a list of lists of length three, it will be treated as an array of points rather than a 3xn array.
- num_points– number of points to sample interpolating function in each direction, when- interpolation_typeis not- default. By default for an \(n\times n\) array this is \(n\).
- **kwds– all other arguments are passed to the surface function
 - OUTPUT: a 3d plot - EXAMPLES: - We plot a matrix that illustrates summation modulo \(n\): - sage: n = 5 sage: list_plot3d(matrix(RDF, n, [(i+j)%n for i in [1..n] for j in [1..n]])) Graphics3d Object - >>> from sage.all import * >>> n = Integer(5) >>> list_plot3d(matrix(RDF, n, [(i+j)%n for i in (ellipsis_range(Integer(1),Ellipsis,n)) for j in (ellipsis_range(Integer(1),Ellipsis,n))])) Graphics3d Object - We plot a matrix of values of - sin:- sage: from math import pi sage: m = matrix(RDF, 6, [sin(i^2 + j^2) ....: for i in [0,pi/5,..,pi] for j in [0,pi/5,..,pi]]) sage: list_plot3d(m, color='yellow', frame_aspect_ratio=[1, 1, 1/3]) Graphics3d Object - >>> from sage.all import * >>> from math import pi >>> m = matrix(RDF, Integer(6), [sin(i**Integer(2) + j**Integer(2)) ... for i in (ellipsis_range(Integer(0),pi/Integer(5),Ellipsis,pi)) for j in (ellipsis_range(Integer(0),pi/Integer(5),Ellipsis,pi))]) >>> list_plot3d(m, color='yellow', frame_aspect_ratio=[Integer(1), Integer(1), Integer(1)/Integer(3)]) Graphics3d Object - Though it does not change the shape of the graph, increasing - num_pointscan increase the clarity of the graph:- sage: list_plot3d(m, color='yellow', num_points=40, ....: frame_aspect_ratio=[1, 1, 1/3]) Graphics3d Object - >>> from sage.all import * >>> list_plot3d(m, color='yellow', num_points=Integer(40), ... frame_aspect_ratio=[Integer(1), Integer(1), Integer(1)/Integer(3)]) Graphics3d Object - We can change the interpolation type: - sage: import warnings sage: warnings.simplefilter('ignore', UserWarning) sage: list_plot3d(m, color='yellow', interpolation_type='clough', ....: frame_aspect_ratio=[1, 1, 1/3]) Graphics3d Object - >>> from sage.all import * >>> import warnings >>> warnings.simplefilter('ignore', UserWarning) >>> list_plot3d(m, color='yellow', interpolation_type='clough', ... frame_aspect_ratio=[Integer(1), Integer(1), Integer(1)/Integer(3)]) Graphics3d Object - We can make this look better by increasing the number of samples: - sage: list_plot3d(m, color='yellow', interpolation_type='clough', ....: frame_aspect_ratio=[1, 1, 1/3], num_points=40) Graphics3d Object - >>> from sage.all import * >>> list_plot3d(m, color='yellow', interpolation_type='clough', ... frame_aspect_ratio=[Integer(1), Integer(1), Integer(1)/Integer(3)], num_points=Integer(40)) Graphics3d Object - Let us try a spline: - sage: list_plot3d(m, color='yellow', interpolation_type='spline', ....: frame_aspect_ratio=[1, 1, 1/3]) Graphics3d Object - >>> from sage.all import * >>> list_plot3d(m, color='yellow', interpolation_type='spline', ... frame_aspect_ratio=[Integer(1), Integer(1), Integer(1)/Integer(3)]) Graphics3d Object - That spline does not capture the oscillation very well; let’s try a higher degree spline: - sage: list_plot3d(m, color='yellow', interpolation_type='spline', degree=5, ....: frame_aspect_ratio=[1, 1, 1/3]) Graphics3d Object - >>> from sage.all import * >>> list_plot3d(m, color='yellow', interpolation_type='spline', degree=Integer(5), ... frame_aspect_ratio=[Integer(1), Integer(1), Integer(1)/Integer(3)]) Graphics3d Object - We plot a list of lists: - sage: show(list_plot3d([[1, 1, 1, 1], [1, 2, 1, 2], [1, 1, 3, 1], [1, 2, 1, 4]])) - >>> from sage.all import * >>> show(list_plot3d([[Integer(1), Integer(1), Integer(1), Integer(1)], [Integer(1), Integer(2), Integer(1), Integer(2)], [Integer(1), Integer(1), Integer(3), Integer(1)], [Integer(1), Integer(2), Integer(1), Integer(4)]])) - We plot a list of points. As a first example we can extract the (x,y,z) coordinates from the above example and make a list plot out of it. By default we do linear interpolation: - sage: l = [] sage: for i in range(6): ....: for j in range(6): ....: l.append((float(i*pi/5), float(j*pi/5), m[i, j])) sage: list_plot3d(l, color='red') Graphics3d Object - >>> from sage.all import * >>> l = [] >>> for i in range(Integer(6)): ... for j in range(Integer(6)): ... l.append((float(i*pi/Integer(5)), float(j*pi/Integer(5)), m[i, j])) >>> list_plot3d(l, color='red') Graphics3d Object - Note that the points do not have to be regularly sampled. For example: - sage: l = [] sage: for i in range(-5, 5): ....: for j in range(-5, 5): ....: l.append((normalvariate(0, 1), ....: normalvariate(0, 1), ....: normalvariate(0, 1))) sage: L = list_plot3d(l, interpolation_type='clough', ....: color='orange', num_points=100) sage: L Graphics3d Object - >>> from sage.all import * >>> l = [] >>> for i in range(-Integer(5), Integer(5)): ... for j in range(-Integer(5), Integer(5)): ... l.append((normalvariate(Integer(0), Integer(1)), ... normalvariate(Integer(0), Integer(1)), ... normalvariate(Integer(0), Integer(1)))) >>> L = list_plot3d(l, interpolation_type='clough', ... color='orange', num_points=Integer(100)) >>> L Graphics3d Object - Check that no NaNs are produced (see Issue #13135): - sage: any(math.isnan(c) for v in L.vertices() for c in v) False - >>> from sage.all import * >>> any(math.isnan(c) for v in L.vertices() for c in v) False 
- sage.plot.plot3d.list_plot3d.list_plot3d_array_of_arrays(v, interpolation_type, **kwds)[source]¶
- A 3-dimensional plot of a surface defined by a list of lists - vdefining points in 3-dimensional space.- This is done by making the list of lists into a matrix and passing back to - list_plot3d(). See- list_plot3d()for full details.- INPUT: - v– list of lists, all the same length
- interpolation_type– (default:- 'linear')
 - OPTIONAL KEYWORDS: - **kwds– all other arguments are passed to the surface function
 - OUTPUT: a 3d plot - EXAMPLES: - The resulting matrix does not have to be square: - sage: show(list_plot3d([[1, 1, 1, 1], [1, 2, 1, 2], [1, 1, 3, 1]])) # indirect doctest - >>> from sage.all import * >>> show(list_plot3d([[Integer(1), Integer(1), Integer(1), Integer(1)], [Integer(1), Integer(2), Integer(1), Integer(2)], [Integer(1), Integer(1), Integer(3), Integer(1)]])) # indirect doctest - The normal route is for the list of lists to be turned into a matrix and use - list_plot3d_matrix():- sage: show(list_plot3d([[1, 1, 1, 1], [1, 2, 1, 2], [1, 1, 3, 1], [1, 2, 1, 4]])) - >>> from sage.all import * >>> show(list_plot3d([[Integer(1), Integer(1), Integer(1), Integer(1)], [Integer(1), Integer(2), Integer(1), Integer(2)], [Integer(1), Integer(1), Integer(3), Integer(1)], [Integer(1), Integer(2), Integer(1), Integer(4)]])) - With certain extra keywords (see - list_plot3d_matrix()), this function will end up using- list_plot3d_tuples():- sage: show(list_plot3d([[1, 1, 1, 1], [1, 2, 1, 2], [1, 1, 3, 1], [1, 2, 1, 4]], ....: interpolation_type='spline')) - >>> from sage.all import * >>> show(list_plot3d([[Integer(1), Integer(1), Integer(1), Integer(1)], [Integer(1), Integer(2), Integer(1), Integer(2)], [Integer(1), Integer(1), Integer(3), Integer(1)], [Integer(1), Integer(2), Integer(1), Integer(4)]], ... interpolation_type='spline')) 
- sage.plot.plot3d.list_plot3d.list_plot3d_matrix(m, **kwds)[source]¶
- A 3-dimensional plot of a surface defined by a matrix - Mdefining points in 3-dimensional space.- See - list_plot3d()for full details.- INPUT: - M– a matrix
 - OPTIONAL KEYWORDS: - **kwds– all other arguments are passed to the surface function
 - OUTPUT: a 3d plot - EXAMPLES: - We plot a matrix that illustrates summation modulo \(n\): - sage: n = 5 sage: list_plot3d(matrix(RDF, n, [(i+j) % n # indirect doctest ....: for i in [1..n] for j in [1..n]])) Graphics3d Object - >>> from sage.all import * >>> n = Integer(5) >>> list_plot3d(matrix(RDF, n, [(i+j) % n # indirect doctest ... for i in (ellipsis_range(Integer(1),Ellipsis,n)) for j in (ellipsis_range(Integer(1),Ellipsis,n))])) Graphics3d Object - The interpolation type for matrices is ‘linear’; for other types use other - list_plot3d()input types.- We plot a matrix of values of \(sin\): - sage: from math import pi sage: m = matrix(RDF, 6, [sin(i^2 + j^2) ....: for i in [0,pi/5,..,pi] for j in [0,pi/5,..,pi]]) sage: list_plot3d(m, color='yellow', frame_aspect_ratio=[1, 1, 1/3]) # indirect doctest Graphics3d Object - >>> from sage.all import * >>> from math import pi >>> m = matrix(RDF, Integer(6), [sin(i**Integer(2) + j**Integer(2)) ... for i in (ellipsis_range(Integer(0),pi/Integer(5),Ellipsis,pi)) for j in (ellipsis_range(Integer(0),pi/Integer(5),Ellipsis,pi))]) >>> list_plot3d(m, color='yellow', frame_aspect_ratio=[Integer(1), Integer(1), Integer(1)/Integer(3)]) # indirect doctest Graphics3d Object - ::
- sage: list_plot3d(m, color=’yellow’, interpolation_type=’linear’) # indirect doctest Graphics3d Object 
 - Here is a colored example, using a colormap and a coloring function which must take values in (0, 1): - sage: cm = colormaps.rainbow sage: n = 20 sage: cf = lambda x, y: ((2*(x-y)/n)**2) % 1 sage: list_plot3d(matrix(RDF, n, [cos(pi*(i+j)/n) for i in [1..n] ....: for j in [1..n]]), color=(cf,cm)) Graphics3d Object - >>> from sage.all import * >>> cm = colormaps.rainbow >>> n = Integer(20) >>> cf = lambda x, y: ((Integer(2)*(x-y)/n)**Integer(2)) % Integer(1) >>> list_plot3d(matrix(RDF, n, [cos(pi*(i+j)/n) for i in (ellipsis_range(Integer(1),Ellipsis,n)) ... for j in (ellipsis_range(Integer(1),Ellipsis,n))]), color=(cf,cm)) Graphics3d Object 
- sage.plot.plot3d.list_plot3d.list_plot3d_tuples(v, interpolation_type, **kwds)[source]¶
- A 3-dimensional plot of a surface defined by the list \(v\) of points in 3-dimensional space. - INPUT: - v– something that defines a set of points in 3 space, for example:- a matrix - This will be if using an - interpolation_typeother than- 'linear', or if using- num_pointswith- 'linear'; otherwise see- list_plot3d_matrix().
- a list of 3-tuples 
- a list of lists (all of the same length, under same conditions as a matrix) 
 
 - OPTIONAL KEYWORDS: - interpolation_type– one of- 'linear',- 'clough'(CloughTocher2D),- 'spline'- 'linear'will perform linear interpolation- The option ‘clough’ will interpolate by using a piecewise cubic interpolating Bezier polynomial on each triangle, using a Clough-Tocher scheme. The interpolant is guaranteed to be continuously differentiable. - The option - 'spline'interpolates using a bivariate B-spline.- When - vis a matrix the default is to use linear interpolation, when- vis a list of points the default is- 'clough'.
- degree– integer between 1 and 5, controls the degree of spline used for spline interpolation. For data that is highly oscillatory use higher values
- point_list– if- point_list=Trueis passed, then if the array is a list of lists of length three, it will be treated as an array of points rather than a \(3\times n\) array.
- num_points– number of points to sample interpolating function in each direction. By default for an \(n\times n\) array this is \(n\).
- **kwds– all other arguments are passed to the surface function
 - OUTPUT: a 3d plot - EXAMPLES: - All of these use this function; see - list_plot3d()for other list plots:- sage: from math import pi sage: m = matrix(RDF, 6, [sin(i^2 + j^2) ....: for i in [0,pi/5,..,pi] for j in [0,pi/5,..,pi]]) sage: list_plot3d(m, color='yellow', interpolation_type='linear', # indirect doctest ....: num_points=5) Graphics3d Object - >>> from sage.all import * >>> from math import pi >>> m = matrix(RDF, Integer(6), [sin(i**Integer(2) + j**Integer(2)) ... for i in (ellipsis_range(Integer(0),pi/Integer(5),Ellipsis,pi)) for j in (ellipsis_range(Integer(0),pi/Integer(5),Ellipsis,pi))]) >>> list_plot3d(m, color='yellow', interpolation_type='linear', # indirect doctest ... num_points=Integer(5)) Graphics3d Object - sage: list_plot3d(m, color='yellow', interpolation_type='spline', ....: frame_aspect_ratio=[1, 1, 1/3]) Graphics3d Object - >>> from sage.all import * >>> list_plot3d(m, color='yellow', interpolation_type='spline', ... frame_aspect_ratio=[Integer(1), Integer(1), Integer(1)/Integer(3)]) Graphics3d Object - sage: show(list_plot3d([[1, 1, 1], [1, 2, 1], [0, 1, 3], [1, 0, 4]], ....: point_list=True)) - >>> from sage.all import * >>> show(list_plot3d([[Integer(1), Integer(1), Integer(1)], [Integer(1), Integer(2), Integer(1)], [Integer(0), Integer(1), Integer(3)], [Integer(1), Integer(0), Integer(4)]], ... point_list=True)) - sage: list_plot3d([(1, 2, 3), (0, 1, 3), (2, 1, 4), (1, 0, -2)], # long time ....: color='yellow', num_points=50) Graphics3d Object - >>> from sage.all import * >>> list_plot3d([(Integer(1), Integer(2), Integer(3)), (Integer(0), Integer(1), Integer(3)), (Integer(2), Integer(1), Integer(4)), (Integer(1), Integer(0), -Integer(2))], # long time ... color='yellow', num_points=Integer(50)) Graphics3d Object