diff --git a/src/sage/plot/bar_chart.py b/src/sage/plot/bar_chart.py index e6cf3136844..dad5afa339f 100644 --- a/src/sage/plot/bar_chart.py +++ b/src/sage/plot/bar_chart.py @@ -31,7 +31,7 @@ class BarChart(GraphicPrimitive): EXAMPLES:: sage: from sage.plot.bar_chart import BarChart - sage: g = BarChart(range(4), [1,3,2,0], {}); g + sage: g = BarChart(list(range(4)), [1,3,2,0], {}); g BarChart defined by a 4 datalist sage: type(g) @@ -43,7 +43,7 @@ def __init__(self, ind, datalist, options): EXAMPLES:: sage: from sage.plot.bar_chart import BarChart - sage: BarChart(range(3), [10,3,5], {'width':0.7}) + sage: BarChart(list(range(3)), [10,3,5], {'width':0.7}) BarChart defined by a 3 datalist """ self.datalist = datalist @@ -74,7 +74,7 @@ def _allowed_options(self): EXAMPLES:: sage: from sage.plot.bar_chart import BarChart - sage: g = BarChart(range(4), [1,3,2,0], {}) + sage: g = BarChart(list(range(4)), [1,3,2,0], {}) sage: list(sorted(g._allowed_options().iteritems())) [('hue', 'The color given as a hue.'), ('legend_label', 'The label for this item in the legend.'), ('rgbcolor', 'The color as an RGB tuple.'), ('width', 'The width of the bars'), ('zorder', 'The layer level in which to draw')] """ @@ -91,7 +91,7 @@ def _repr_(self): EXAMPLES:: sage: from sage.plot.bar_chart import BarChart - sage: g = BarChart(range(4), [1,3,2,0], {}) + sage: g = BarChart(list(range(4)), [1,3,2,0], {}) sage: g._repr_() 'BarChart defined by a 4 datalist' """ @@ -177,7 +177,7 @@ def bar_chart(datalist, **options): # g._bar_chart(ind, pnts, xrange, yrange, options=options) # cnt += 1 #else: - ind = range(len(datalist)) + ind = list(range(len(datalist))) g.add_primitive(BarChart(ind, datalist, options=options)) if options['legend_label']: g.legend(True) diff --git a/src/sage/plot/graphics.py b/src/sage/plot/graphics.py index c5a38e7c7bb..c1fa85ef12f 100644 --- a/src/sage/plot/graphics.py +++ b/src/sage/plot/graphics.py @@ -1741,7 +1741,7 @@ def show(self, filename=None, linkmode=False, **kwds): sage: def maple_leaf(t): ....: return (100/(100+(t-pi/2)^8))*(2-sin(7*t)-cos(30*t)/2) sage: p = polar_plot(maple_leaf, -pi/4, 3*pi/2, color="red",plot_points=1000) # long time - sage: p.show(gridlines=( [-3,-2.75,..,3], xrange(-1,5,2) )) # long time + sage: p.show(gridlines=([-3,-2.75,..,3], range(-1,5,2))) # long time Add grid lines at specific positions (using functions). diff --git a/src/sage/plot/histogram.py b/src/sage/plot/histogram.py index 7826f5507f7..02be37e783a 100644 --- a/src/sage/plot/histogram.py +++ b/src/sage/plot/histogram.py @@ -31,7 +31,7 @@ class Histogram(GraphicPrimitive): sage: type(g) sage: opts = { 'bins':20, 'label':'mydata'} - sage: g = Histogram([random() for _ in xrange(500)], opts); g + sage: g = Histogram([random() for _ in range(500)], opts); g Histogram defined by a data list of size 500 We can accept multiple sets of the same length:: @@ -68,10 +68,10 @@ def get_minmax_data(self): sage: H = histogram([10,3,5], normed=True); h = H[0] sage: h.get_minmax_data() {'xmax': 10.0, 'xmin': 3.0, 'ymax': 0.4761904761904765, 'ymin': 0} - sage: G = histogram([random() for _ in xrange(500)]); g = G[0] + sage: G = histogram([random() for _ in range(500)]); g = G[0] sage: g.get_minmax_data() # random output {'xmax': 0.99729312925213209, 'xmin': 0.00013024562219410285, 'ymax': 61, 'ymin': 0} - sage: Y = histogram([random()*10 for _ in xrange(500)], range=[2,8]); y = Y[0] + sage: Y = histogram([random()*10 for _ in range(500)], range=[2,8]); y = Y[0] sage: ymm = y.get_minmax_data(); ymm['xmax'], ymm['xmin'] (8.0, 2.0) sage: Z = histogram([[1,3,2,0], [4,4,3,3]]); z = Z[0] @@ -248,7 +248,7 @@ def histogram(datalist, **options): looks like the probability density function:: sage: nv = normalvariate - sage: H = histogram([nv(0,1) for _ in xrange(1000)], bins=20, normed=True, range=[-5,5]) + sage: H = histogram([nv(0,1) for _ in range(1000)], bins=20, normed=True, range=[-5,5]) sage: P = plot( 1/sqrt(2*pi)*e^(-x^2/2), (x,-5,5), color='red', linestyle='--') sage: H+P Graphics object consisting of 2 graphics primitives @@ -256,7 +256,7 @@ def histogram(datalist, **options): There are many options one can use with histograms. Some of these control the presentation of the data, even if it is boring:: - sage: histogram(range(100), color=(1,0,0), label='mydata',\ + sage: histogram(list(range(100)), color=(1,0,0), label='mydata',\ rwidth=.5, align="right") Graphics object consisting of 1 graphics primitive @@ -271,7 +271,7 @@ def histogram(datalist, **options): We can do several data sets at once if desired:: - sage: histogram([srange(0,1,.1)*10, [nv(0, 1) for _ in xrange(100)]], color=['red','green'], bins=5) + sage: histogram([srange(0,1,.1)*10, [nv(0, 1) for _ in range(100)]], color=['red','green'], bins=5) Graphics object consisting of 1 graphics primitive We have the option of stacking the data sets too:: @@ -281,11 +281,9 @@ def histogram(datalist, **options): It is possible to use weights with the histogram as well:: - sage: histogram(range(10), bins=3, weights=[1,2,3,4,5,5,4,3,2,1]) + sage: histogram(list(range(10)), bins=3, weights=[1,2,3,4,5,5,4,3,2,1]) Graphics object consisting of 1 graphics primitive - """ - g = Graphics() g._set_extra_kwds(Graphics._extract_kwds_for_show(options)) g.add_primitive(Histogram(datalist, options=options)) diff --git a/src/sage/plot/matrix_plot.py b/src/sage/plot/matrix_plot.py index fae0bd2df2b..e55338d0529 100644 --- a/src/sage/plot/matrix_plot.py +++ b/src/sage/plot/matrix_plot.py @@ -408,7 +408,7 @@ def matrix_plot(mat, **options): Here we plot a random sparse matrix:: - sage: sparse = matrix(dict([((randint(0, 10), randint(0, 10)), 1) for i in xrange(100)])) + sage: sparse = matrix(dict([((randint(0, 10), randint(0, 10)), 1) for i in range(100)])) sage: matrix_plot(sparse) Graphics object consisting of 1 graphics primitive diff --git a/src/sage/plot/plot.py b/src/sage/plot/plot.py index 315b6af09f6..582daa6be61 100644 --- a/src/sage/plot/plot.py +++ b/src/sage/plot/plot.py @@ -332,10 +332,9 @@ sage: g = Graphics() sage: for i in range(60): - ... p = polygon([(i*cos(i),i*sin(i)), (0,i), (i,0)],\ - ... color=hue(i/40+0.4), alpha=0.2) - ... g = g + p - ... + ....: p = polygon([(i*cos(i),i*sin(i)), (0,i), (i,0)],\ + ....: color=hue(i/40+0.4), alpha=0.2) + ....: g = g + p sage: g.show(dpi=200, axes=False) .. PLOT:: @@ -549,6 +548,7 @@ def f(x): return (x-3)*(x-5)*(x-7)+40 #***************************************************************************** from __future__ import print_function from __future__ import absolute_import +from six.moves import range import os from functools import reduce @@ -1708,7 +1708,7 @@ def b(n): return lambda x: bessel_J(n, x) + 0.5*(n-1) .. PLOT:: - g = plot(floor(x), (x, 1, 10), exclude=range(1,11)) + g = plot(floor(x), (x, 1, 10), exclude=list(range(1,11))) sphinx_plot(g) We exclude all points where :class:`~sage.functions.prime_pi.PrimePi` @@ -1750,7 +1750,7 @@ def g(x): return x**2-2*x-2 .. PLOT:: def f(x): return (floor(x)+0.5) / (1-(x-0.5)**2) - g = plot(f, (x, -3.5, 3.5), detect_poles='show', exclude=range(-3,4), ymin=-5, ymax=5) + g = plot(f, (x, -3.5, 3.5), detect_poles='show', exclude=list(range(-3,4)), ymin=-5, ymax=5) sphinx_plot(g) Regions in which the plot has no values are automatically excluded. The @@ -2717,7 +2717,7 @@ def polar_plot(funcs, *args, **kwds): .. PLOT:: - g = polar_plot(log(floor(x)), (x, 1, 4*pi), exclude=range(1,13)) + g = polar_plot(log(floor(x)), (x, 1, 4*pi), exclude=list(range(1,13))) sphinx_plot(g) """ @@ -3376,7 +3376,7 @@ def reshape(v, n, m): # Now v should be a single list. # First, make it have the right length. v = list(v) # do not mutate the argument - for i in xrange(n*m - len(v)): + for i in range(n * m - len(v)): v.append(G) # Next, create a list of lists out of it. @@ -3554,7 +3554,7 @@ def var_and_list_of_values(v, plot_points): return var, [a, b] else: step = (b-a)/float(plot_points-1) - values = [a + step*i for i in xrange(plot_points)] + values = [a + step * i for i in range(plot_points)] return var, values diff --git a/src/sage/plot/plot3d/list_plot3d.py b/src/sage/plot/plot3d/list_plot3d.py index 366eb153249..4aaf8f90aae 100644 --- a/src/sage/plot/plot3d/list_plot3d.py +++ b/src/sage/plot/plot3d/list_plot3d.py @@ -2,6 +2,8 @@ List Plots """ from __future__ import absolute_import +from six.moves import range + from sage.matrix.matrix import is_Matrix from sage.matrix.all import matrix from sage.rings.all import RDF @@ -128,8 +130,8 @@ def list_plot3d(v, interpolation_type='default', texture="automatic", point_list 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])) + ....: for j in range(6): + ....: l.append((float(i*pi/5), float(j*pi/5), m[i, j])) sage: list_plot3d(l, texture='yellow') Graphics3d Object @@ -137,8 +139,8 @@ def list_plot3d(v, interpolation_type='default', texture="automatic", point_list 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))) + ....: for j in range(-5, 5): + ....: l.append((normalvariate(0, 1), normalvariate(0, 1), normalvariate(0, 1))) sage: list_plot3d(l, interpolation_type='nn', texture='yellow', num_points=100) Graphics3d Object @@ -184,8 +186,8 @@ def list_plot3d(v, interpolation_type='default', texture="automatic", point_list return list_plot3d_matrix(v, texture=texture, **kwds) else: l = [] - for i in xrange(v.nrows()): - for j in xrange(v.ncols()): + for i in range(v.nrows()): + for j in range(v.ncols()): l.append((i, j, v[i, j])) return list_plot3d_tuples(l, interpolation_type, texture, **kwds) @@ -250,7 +252,8 @@ def list_plot3d_matrix(m, texture, **kwds): """ from .parametric_surface import ParametricSurface f = lambda i,j: (i, j, float(m[int(i), int(j)])) - G = ParametricSurface(f, (range(m.nrows()), range(m.ncols())), texture=texture, **kwds) + G = ParametricSurface(f, (list(range(m.nrows())), list(range(m.ncols()))), + texture=texture, **kwds) G._set_extra_kwds(kwds) return G diff --git a/src/sage/plot/polygon.py b/src/sage/plot/polygon.py index 728d6113197..2a52a2db5a7 100644 --- a/src/sage/plot/polygon.py +++ b/src/sage/plot/polygon.py @@ -17,6 +17,8 @@ # # http://www.gnu.org/licenses/ #***************************************************************************** +from six.moves import range + from sage.plot.primitive import GraphicPrimitive_xydata from sage.misc.decorators import options, rename_keyword from sage.plot.colors import to_mpl_color @@ -240,7 +242,8 @@ def _render_on_subplot(self, subplot): """ import matplotlib.patches as patches options = self.options() - p = patches.Polygon([(self.xdata[i],self.ydata[i]) for i in xrange(len(self.xdata))]) + p = patches.Polygon([(self.xdata[i],self.ydata[i]) + for i in range(len(self.xdata))]) p.set_linewidth(float(options['thickness'])) a = float(options['alpha']) z = int(options.pop('zorder', 1))