Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
trac 21548 get rid of xrange in plot folder
Browse files Browse the repository at this point in the history
  • Loading branch information
Frédéric Chapoton committed Sep 20, 2016
1 parent 0ae5fd8 commit e216204
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 33 deletions.
10 changes: 5 additions & 5 deletions src/sage/plot/bar_chart.py
Expand Up @@ -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)
<class 'sage.plot.bar_chart.BarChart'>
Expand All @@ -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
Expand Down Expand Up @@ -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')]
"""
Expand All @@ -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'
"""
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/sage/plot/graphics.py
Expand Up @@ -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).
Expand Down
16 changes: 7 additions & 9 deletions src/sage/plot/histogram.py
Expand Up @@ -31,7 +31,7 @@ class Histogram(GraphicPrimitive):
sage: type(g)
<class 'sage.plot.histogram.Histogram'>
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::
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -248,15 +248,15 @@ 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
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
Expand All @@ -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::
Expand All @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion src/sage/plot/matrix_plot.py
Expand Up @@ -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
Expand Down
18 changes: 9 additions & 9 deletions src/sage/plot/plot.py
Expand Up @@ -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::
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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`
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
"""
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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


Expand Down
17 changes: 10 additions & 7 deletions src/sage/plot/plot3d/list_plot3d.py
Expand Up @@ -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
Expand Down Expand Up @@ -128,17 +130,17 @@ 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
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)))
....: 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
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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

Expand Down
5 changes: 4 additions & 1 deletion src/sage/plot/polygon.py
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit e216204

Please sign in to comment.