def plot_histogram(self, clr=(0,0,1), eps = 0.4): r""" Plot the histogram plot of the sequence. The sequence is assumed to be real or from a finite field, with a real indexing set ``I`` coercible into `\RR`. Options are ``clr``, which is an RGB value, and ``eps``, which is the spacing between the bars. EXAMPLES:: sage: J = range(3) sage: A = [ZZ(i^2)+1 for i in J] sage: s = IndexedSequence(A,J) sage: P = s.plot_histogram() sage: show(P) # Not tested """ # elements must be coercible into RR I = self.index_object() N = len(I) S = self.list() P = [polygon([[RR(I[i])-eps,0],[RR(I[i])-eps,RR(S[i])],[RR(I[i])+eps,RR(S[i])],[RR(I[i])+eps,0],[RR(I[i]),0]], rgbcolor=clr) for i in range(N)] T = [text(str(I[i]),(RR(I[i]),-0.8),fontsize=15,rgbcolor=(1,0,0)) for i in range(N)] return sum(P) + sum(T)
def plot_histogram(self, clr=(0, 0, 1), eps=0.4): """ Plots the histogram plot of the sequence, which is assumed to be real or from a finite field, with a real indexing set I coercible into RR. Options are clr, which is an RGB value, and eps, which is the spacing between the bars. EXAMPLES: sage: J = range(3) sage: A = [ZZ(i^2)+1 for i in J] sage: s = IndexedSequence(A,J) sage: P = s.plot_histogram() Now type show(P) to view this in a browser. """ #from sage.plot.misc import text F = self.base_ring() ## elements must be coercible into RR I = self.index_object() N = len(I) S = self.list() P = [ polygon([[RR(I[i]) - eps, 0], [ RR(I[i]) - eps, RR(S[i]) ], [RR(I[i]) + eps, RR(S[i])], [RR(I[i]) + eps, 0], [RR(I[i]), 0]], rgbcolor=clr) for i in range(N) ] T = [ text(str(I[i]), (RR(I[i]), -0.8), fontsize=15, rgbcolor=(1, 0, 0)) for i in range(N) ] return sum(P) + sum(T)
def plot(self, xrange, **options): r""" Plot this function. The plot is intended to give an idea of the accuracy of the evaluations that led to it. However, it may not be a rigorous enclosure of the graph of the function. EXAMPLES:: sage: from ore_algebra import * sage: from ore_algebra.analytic.function import DFiniteFunction sage: DiffOps, x, Dx = DifferentialOperators() sage: f = DFiniteFunction(Dx^2 - x, ....: [1/(gamma(2/3)*3^(2/3)), -1/(gamma(1/3)*3^(1/3))]) sage: plot(f, (-10, 5), color='black') Graphics object consisting of 1 graphics primitive """ mids = generate_plot_points(lambda x: self.approx(x, 20).mid(), xrange, plot_points=200) ivs = [(x, self.approx(x, 20)) for x, _ in mids] bounds = [(x, y.upper()) for x, y in ivs] bounds += [(x, y.lower()) for x, y in reversed(ivs)] options.setdefault('aspect_ratio', 'automatic') g = plot.polygon(bounds, thickness=1, **options) return g
def sector(ray1, ray2, **extra_options): r""" Plot a sector between ``ray1`` and ``ray2`` centered at the origin. .. NOTE:: This function was intended for plotting strictly convex cones, so it plots the smaller sector between ``ray1`` and ``ray2`` and, therefore, they cannot be opposite. If you do want to use this function for bigger regions, split them into several parts. .. NOTE:: As of version 4.6 Sage does not have a graphic primitive for sectors in 3-dimensional space, so this function will actually approximate them using polygons (the number of vertices used depends on the angle between rays). INPUT: - ``ray1``, ``ray2`` -- rays in 2- or 3-dimensional space of the same length; - ``extra_options`` -- a dictionary of options that should be passed to lower level plotting functions. OUTPUT: - a plot. EXAMPLES:: sage: from sage.geometry.toric_plotter import sector sage: print sector((1,0), (0,1)) Graphics object consisting of 1 graphics primitive sage: print sector((3,2,1), (1,2,3)) Graphics3d Object """ ray1 = vector(RDF, ray1) ray2 = vector(RDF, ray2) r = ray1.norm() if len(ray1) == 2: # Plot an honest sector phi1 = arctan2(ray1[1], ray1[0]) phi2 = arctan2(ray2[1], ray2[0]) if phi1 > phi2: phi1, phi2 = phi2, phi1 if phi2 - phi1 > pi: phi1, phi2 = phi2, phi1 + 2 * pi return disk((0, 0), r, (phi1, phi2), **extra_options) else: # Plot a polygon, 30 vertices per radian. vertices_per_radian = 30 n = ceil(arccos(ray1 * ray2 / r**2) * vertices_per_radian) dr = (ray2 - ray1) / n points = (ray1 + i * dr for i in range(n + 1)) points = [r / pt.norm() * pt for pt in points] points.append(vector(RDF, 3)) return polygon(points, **extra_options)
def sector(ray1, ray2, **extra_options): r""" Plot a sector between ``ray1`` and ``ray2`` centered at the origin. .. NOTE:: This function was intended for plotting strictly convex cones, so it plots the smaller sector between ``ray1`` and ``ray2`` and, therefore, they cannot be opposite. If you do want to use this function for bigger regions, split them into several parts. .. NOTE:: As of version 4.6 Sage does not have a graphic primitive for sectors in 3-dimensional space, so this function will actually approximate them using polygons (the number of vertices used depends on the angle between rays). INPUT: - ``ray1``, ``ray2`` -- rays in 2- or 3-dimensional space of the same length; - ``extra_options`` -- a dictionary of options that should be passed to lower level plotting functions. OUTPUT: - a plot. EXAMPLES:: sage: from sage.geometry.toric_plotter import sector sage: sector((1,0), (0,1)) Graphics object consisting of 1 graphics primitive sage: sector((3,2,1), (1,2,3)) Graphics3d Object """ ray1 = vector(RDF, ray1) ray2 = vector(RDF, ray2) r = ray1.norm() if len(ray1) == 2: # Plot an honest sector phi1 = arctan2(ray1[1], ray1[0]) phi2 = arctan2(ray2[1], ray2[0]) if phi1 > phi2: phi1, phi2 = phi2, phi1 if phi2 - phi1 > pi: phi1, phi2 = phi2, phi1 + 2 * pi return disk((0,0), r, (phi1, phi2), **extra_options) else: # Plot a polygon, 30 vertices per radian. vertices_per_radian = 30 n = ceil(arccos(ray1 * ray2 / r**2) * vertices_per_radian) dr = (ray2 - ray1) / n points = (ray1 + i * dr for i in range(n + 1)) points = [r / pt.norm() * pt for pt in points] points.append(vector(RDF, 3)) return polygon(points, **extra_options)
def plot_histogram(self, clr=(0,0,1),eps = 0.4): """ Plots the histogram plot of the sequence, which is assumed to be real or from a finite field, with a real indexing set I coercible into RR. Options are clr, which is an RGB value, and eps, which is the spacing between the bars. EXAMPLES: sage: J = range(3) sage: A = [ZZ(i^2)+1 for i in J] sage: s = IndexedSequence(A,J) sage: P = s.plot_histogram() Now type show(P) to view this in a browser. """ #from sage.plot.misc import text F = self.base_ring() ## elements must be coercible into RR I = self.index_object() N = len(I) S = self.list() P = [polygon([[RR(I[i])-eps,0],[RR(I[i])-eps,RR(S[i])],[RR(I[i])+eps,RR(S[i])],[RR(I[i])+eps,0],[RR(I[i]),0]], rgbcolor=clr) for i in range(N)] T = [text(str(I[i]),(RR(I[i]),-0.8),fontsize=15,rgbcolor=(1,0,0)) for i in range(N)] return sum(P)+sum(T)