passagemath-plot 10.6.31rc3__cp314-cp314-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of passagemath-plot might be problematic. Click here for more details.
- passagemath_plot-10.6.31rc3.dist-info/METADATA +172 -0
- passagemath_plot-10.6.31rc3.dist-info/RECORD +81 -0
- passagemath_plot-10.6.31rc3.dist-info/WHEEL +6 -0
- passagemath_plot-10.6.31rc3.dist-info/top_level.txt +2 -0
- passagemath_plot.libs/libgfortran-e1b7dfc8.so.5.0.0 +0 -0
- passagemath_plot.libs/libgsl-e3525837.so.28.0.0 +0 -0
- passagemath_plot.libs/libopenblasp-r0-4c5b64b1.3.29.so +0 -0
- sage/all__sagemath_plot.py +15 -0
- sage/ext_data/threejs/animation.css +195 -0
- sage/ext_data/threejs/animation.html +85 -0
- sage/ext_data/threejs/animation.js +273 -0
- sage/ext_data/threejs/fat_lines.js +48 -0
- sage/ext_data/threejs/threejs-version.txt +1 -0
- sage/ext_data/threejs/threejs_template.html +597 -0
- sage/interfaces/all__sagemath_plot.py +1 -0
- sage/interfaces/gnuplot.py +196 -0
- sage/interfaces/jmoldata.py +208 -0
- sage/interfaces/povray.py +56 -0
- sage/plot/all.py +42 -0
- sage/plot/animate.py +1796 -0
- sage/plot/arc.py +504 -0
- sage/plot/arrow.py +671 -0
- sage/plot/bar_chart.py +205 -0
- sage/plot/bezier_path.py +400 -0
- sage/plot/circle.py +435 -0
- sage/plot/colors.py +1606 -0
- sage/plot/complex_plot.cpython-314-aarch64-linux-gnu.so +0 -0
- sage/plot/complex_plot.pyx +1446 -0
- sage/plot/contour_plot.py +1792 -0
- sage/plot/density_plot.py +318 -0
- sage/plot/disk.py +373 -0
- sage/plot/ellipse.py +375 -0
- sage/plot/graphics.py +3580 -0
- sage/plot/histogram.py +354 -0
- sage/plot/hyperbolic_arc.py +404 -0
- sage/plot/hyperbolic_polygon.py +416 -0
- sage/plot/hyperbolic_regular_polygon.py +296 -0
- sage/plot/line.py +626 -0
- sage/plot/matrix_plot.py +629 -0
- sage/plot/misc.py +509 -0
- sage/plot/multigraphics.py +1294 -0
- sage/plot/plot.py +4183 -0
- sage/plot/plot3d/all.py +23 -0
- sage/plot/plot3d/base.cpython-314-aarch64-linux-gnu.so +0 -0
- sage/plot/plot3d/base.pxd +12 -0
- sage/plot/plot3d/base.pyx +3378 -0
- sage/plot/plot3d/implicit_plot3d.py +659 -0
- sage/plot/plot3d/implicit_surface.cpython-314-aarch64-linux-gnu.so +0 -0
- sage/plot/plot3d/implicit_surface.pyx +1453 -0
- sage/plot/plot3d/index_face_set.cpython-314-aarch64-linux-gnu.so +0 -0
- sage/plot/plot3d/index_face_set.pxd +32 -0
- sage/plot/plot3d/index_face_set.pyx +1873 -0
- sage/plot/plot3d/introduction.py +131 -0
- sage/plot/plot3d/list_plot3d.py +649 -0
- sage/plot/plot3d/parametric_plot3d.py +1130 -0
- sage/plot/plot3d/parametric_surface.cpython-314-aarch64-linux-gnu.so +0 -0
- sage/plot/plot3d/parametric_surface.pxd +12 -0
- sage/plot/plot3d/parametric_surface.pyx +893 -0
- sage/plot/plot3d/platonic.py +601 -0
- sage/plot/plot3d/plot3d.py +1442 -0
- sage/plot/plot3d/plot_field3d.py +162 -0
- sage/plot/plot3d/point_c.pxi +148 -0
- sage/plot/plot3d/revolution_plot3d.py +309 -0
- sage/plot/plot3d/shapes.cpython-314-aarch64-linux-gnu.so +0 -0
- sage/plot/plot3d/shapes.pxd +22 -0
- sage/plot/plot3d/shapes.pyx +1382 -0
- sage/plot/plot3d/shapes2.py +1512 -0
- sage/plot/plot3d/tachyon.py +1779 -0
- sage/plot/plot3d/texture.py +453 -0
- sage/plot/plot3d/transform.cpython-314-aarch64-linux-gnu.so +0 -0
- sage/plot/plot3d/transform.pxd +21 -0
- sage/plot/plot3d/transform.pyx +268 -0
- sage/plot/plot3d/tri_plot.py +589 -0
- sage/plot/plot_field.py +362 -0
- sage/plot/point.py +624 -0
- sage/plot/polygon.py +562 -0
- sage/plot/primitive.py +249 -0
- sage/plot/scatter_plot.py +199 -0
- sage/plot/step.py +85 -0
- sage/plot/streamline_plot.py +328 -0
- sage/plot/text.py +432 -0
sage/plot/histogram.py
ADDED
|
@@ -0,0 +1,354 @@
|
|
|
1
|
+
# sage_setup: distribution = sagemath-plot
|
|
2
|
+
"""
|
|
3
|
+
Histograms
|
|
4
|
+
"""
|
|
5
|
+
# ****************************************************************************
|
|
6
|
+
# Distributed under the terms of the GNU General Public License (GPL)
|
|
7
|
+
#
|
|
8
|
+
# This code is distributed in the hope that it will be useful,
|
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
11
|
+
# General Public License for more details.
|
|
12
|
+
#
|
|
13
|
+
# The full text of the GPL is available at:
|
|
14
|
+
#
|
|
15
|
+
# https://www.gnu.org/licenses/
|
|
16
|
+
# ****************************************************************************
|
|
17
|
+
from sage.plot.primitive import GraphicPrimitive
|
|
18
|
+
from sage.plot.plot import minmax_data, Graphics
|
|
19
|
+
from sage.misc.decorators import options
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class Histogram(GraphicPrimitive):
|
|
23
|
+
"""
|
|
24
|
+
Graphics primitive that represents a histogram. This takes
|
|
25
|
+
quite a few options as well.
|
|
26
|
+
|
|
27
|
+
EXAMPLES::
|
|
28
|
+
|
|
29
|
+
sage: from sage.plot.histogram import Histogram
|
|
30
|
+
sage: g = Histogram([1,3,2,0], {}); g
|
|
31
|
+
Histogram defined by a data list of size 4
|
|
32
|
+
sage: type(g)
|
|
33
|
+
<class 'sage.plot.histogram.Histogram'>
|
|
34
|
+
sage: opts = { 'bins':20, 'label':'mydata'}
|
|
35
|
+
sage: g = Histogram([random() for _ in range(500)], opts); g
|
|
36
|
+
Histogram defined by a data list of size 500
|
|
37
|
+
|
|
38
|
+
We can accept multiple sets of the same length::
|
|
39
|
+
|
|
40
|
+
sage: g = Histogram([[1,3,2,0], [4,4,3,3]], {}); g
|
|
41
|
+
Histogram defined by 2 data lists
|
|
42
|
+
"""
|
|
43
|
+
def __init__(self, datalist, options):
|
|
44
|
+
"""
|
|
45
|
+
Initialize a ``Histogram`` primitive along with
|
|
46
|
+
its options.
|
|
47
|
+
|
|
48
|
+
EXAMPLES::
|
|
49
|
+
|
|
50
|
+
sage: from sage.plot.histogram import Histogram
|
|
51
|
+
sage: Histogram([10,3,5], {'width':0.7})
|
|
52
|
+
Histogram defined by a data list of size 3
|
|
53
|
+
"""
|
|
54
|
+
import numpy as np
|
|
55
|
+
self.datalist = np.asarray(datalist, dtype=float)
|
|
56
|
+
if 'normed' in options:
|
|
57
|
+
from sage.misc.superseded import deprecation
|
|
58
|
+
deprecation(25260, "the 'normed' option is deprecated. Use 'density' instead.")
|
|
59
|
+
if 'linestyle' in options:
|
|
60
|
+
from sage.plot.misc import get_matplotlib_linestyle
|
|
61
|
+
options['linestyle'] = get_matplotlib_linestyle(
|
|
62
|
+
options['linestyle'], return_type='long')
|
|
63
|
+
if options.get('range', None):
|
|
64
|
+
# numpy.histogram performs type checks on "range" so this must be
|
|
65
|
+
# actual floats
|
|
66
|
+
options['range'] = [float(x) for x in options['range']]
|
|
67
|
+
GraphicPrimitive.__init__(self, options)
|
|
68
|
+
|
|
69
|
+
def get_minmax_data(self):
|
|
70
|
+
"""
|
|
71
|
+
Get minimum and maximum horizontal and vertical ranges
|
|
72
|
+
for the Histogram object.
|
|
73
|
+
|
|
74
|
+
EXAMPLES::
|
|
75
|
+
|
|
76
|
+
sage: H = histogram([10,3,5], density=True); h = H[0]
|
|
77
|
+
sage: h.get_minmax_data() # rel tol 1e-15
|
|
78
|
+
{'xmax': 10.0, 'xmin': 3.0, 'ymax': 0.4761904761904765, 'ymin': 0}
|
|
79
|
+
sage: G = histogram([random() for _ in range(500)]); g = G[0]
|
|
80
|
+
sage: g.get_minmax_data() # random output
|
|
81
|
+
{'xmax': 0.99729312925213209, 'xmin': 0.00013024562219410285, 'ymax': 61, 'ymin': 0}
|
|
82
|
+
sage: Y = histogram([random()*10 for _ in range(500)], range=[2,8]); y = Y[0]
|
|
83
|
+
sage: ymm = y.get_minmax_data(); ymm['xmax'], ymm['xmin']
|
|
84
|
+
(8.0, 2.0)
|
|
85
|
+
sage: Z = histogram([[1,3,2,0], [4,4,3,3]]); z = Z[0]
|
|
86
|
+
sage: z.get_minmax_data()
|
|
87
|
+
{'xmax': 4.0, 'xmin': 0, 'ymax': 2, 'ymin': 0}
|
|
88
|
+
|
|
89
|
+
TESTS::
|
|
90
|
+
|
|
91
|
+
sage: h = histogram([10,3,5], density=True)[0]
|
|
92
|
+
sage: h.get_minmax_data()
|
|
93
|
+
{'xmax': 10.0, 'xmin': 3.0, 'ymax': 0.476190476190..., 'ymin': 0}
|
|
94
|
+
"""
|
|
95
|
+
import numpy
|
|
96
|
+
if int(numpy.version.short_version[0]) > 1:
|
|
97
|
+
numpy.set_printoptions(legacy="1.25")
|
|
98
|
+
|
|
99
|
+
# Extract these options (if they are not None) and pass them to
|
|
100
|
+
# histogram()
|
|
101
|
+
options = self.options()
|
|
102
|
+
opt = {}
|
|
103
|
+
for key in ('range', 'bins', 'normed', 'density', 'weights'):
|
|
104
|
+
try:
|
|
105
|
+
value = options[key]
|
|
106
|
+
except KeyError:
|
|
107
|
+
pass
|
|
108
|
+
else:
|
|
109
|
+
if value is not None:
|
|
110
|
+
opt[key] = value
|
|
111
|
+
|
|
112
|
+
# check to see if a list of datasets
|
|
113
|
+
if not hasattr(self.datalist[0], '__contains__'):
|
|
114
|
+
ydata, xdata = numpy.histogram(self.datalist, **opt)
|
|
115
|
+
return minmax_data(xdata, [0]+list(ydata), dict=True)
|
|
116
|
+
else:
|
|
117
|
+
m = {'xmax': 0, 'xmin': 0, 'ymax': 0, 'ymin': 0}
|
|
118
|
+
if not options.get('stacked'):
|
|
119
|
+
for d in self.datalist:
|
|
120
|
+
ydata, xdata = numpy.histogram(d, **opt)
|
|
121
|
+
m['xmax'] = max([m['xmax']] + list(xdata))
|
|
122
|
+
m['xmin'] = min([m['xmin']] + list(xdata))
|
|
123
|
+
m['ymax'] = max([m['ymax']] + list(ydata))
|
|
124
|
+
return m
|
|
125
|
+
else:
|
|
126
|
+
for d in self.datalist:
|
|
127
|
+
ydata, xdata = numpy.histogram(d, **opt)
|
|
128
|
+
m['xmax'] = max([m['xmax']] + list(xdata))
|
|
129
|
+
m['xmin'] = min([m['xmin']] + list(xdata))
|
|
130
|
+
m['ymax'] = m['ymax'] + max(list(ydata))
|
|
131
|
+
return m
|
|
132
|
+
|
|
133
|
+
def _allowed_options(self):
|
|
134
|
+
"""
|
|
135
|
+
Return the allowed options with descriptions for this graphics
|
|
136
|
+
primitive. This is used in displaying an error message when the
|
|
137
|
+
user gives an option that doesn't make sense.
|
|
138
|
+
|
|
139
|
+
EXAMPLES::
|
|
140
|
+
|
|
141
|
+
sage: from sage.plot.histogram import Histogram
|
|
142
|
+
sage: g = Histogram( [1,3,2,0], {})
|
|
143
|
+
sage: L = list(sorted(g._allowed_options().items()))
|
|
144
|
+
sage: L[0]
|
|
145
|
+
('align',
|
|
146
|
+
'How the bars align inside of each bin. Acceptable values are "left", "right" or "mid".')
|
|
147
|
+
sage: L[-1]
|
|
148
|
+
('zorder', 'The layer level to draw the histogram')
|
|
149
|
+
"""
|
|
150
|
+
return {'color': 'The color of the face of the bars or list of colors if multiple data sets are given.',
|
|
151
|
+
'edgecolor': 'The color of the border of each bar.',
|
|
152
|
+
'alpha': 'How transparent the plot is',
|
|
153
|
+
'hue': 'The color of the bars given as a hue.',
|
|
154
|
+
'fill': '(True or False, default: ``True``) Whether to fill the bars',
|
|
155
|
+
'hatch': 'What symbol to fill with - one of "/", "\\", "|", "-", "+", "x", "o", "O", ".", "*"',
|
|
156
|
+
'linewidth': 'Width of the lines defining the bars',
|
|
157
|
+
'linestyle': "One of 'solid' or '-', 'dashed' or '--', 'dotted' or ':', 'dashdot' or '-.'",
|
|
158
|
+
'zorder': 'The layer level to draw the histogram',
|
|
159
|
+
'bins': 'The number of sections in which to divide the range. Also can be a sequence of points within the range that create the partition.',
|
|
160
|
+
'align': 'How the bars align inside of each bin. Acceptable values are "left", "right" or "mid".',
|
|
161
|
+
'rwidth': 'The relative width of the bars as a fraction of the bin width',
|
|
162
|
+
'cumulative': '(True or False) If True, then a histogram is computed in which each bin gives the counts in that bin plus all bins for smaller values. Negative values give a reversed direction of accumulation.',
|
|
163
|
+
'range': 'A list [min, max] which define the range of the histogram. Values outside of this range are treated as outliers and omitted from counts.',
|
|
164
|
+
'normed': 'Deprecated. Use density instead.',
|
|
165
|
+
'density': '(True or False) If True, the counts are normalized to form a probability density. (n/(len(x)*dbin)',
|
|
166
|
+
'weights': 'A sequence of weights the same length as the data list. If supplied, then each value contributes its associated weight to the bin count.',
|
|
167
|
+
'stacked': '(True or False) If True, multiple data are stacked on top of each other.',
|
|
168
|
+
'label': 'A string label for each data list given.'}
|
|
169
|
+
|
|
170
|
+
def _repr_(self):
|
|
171
|
+
"""
|
|
172
|
+
Return text representation of this histogram graphics primitive.
|
|
173
|
+
|
|
174
|
+
EXAMPLES::
|
|
175
|
+
|
|
176
|
+
sage: from sage.plot.histogram import Histogram
|
|
177
|
+
sage: g = Histogram( [1,3,2,0], {})
|
|
178
|
+
sage: g._repr_()
|
|
179
|
+
'Histogram defined by a data list of size 4'
|
|
180
|
+
sage: g = Histogram( [[1,1,2,3], [1,3,2,0]], {})
|
|
181
|
+
sage: g._repr_()
|
|
182
|
+
'Histogram defined by 2 data lists'
|
|
183
|
+
"""
|
|
184
|
+
L = len(self.datalist)
|
|
185
|
+
if not hasattr(self.datalist[0], '__contains__'):
|
|
186
|
+
return f"Histogram defined by a data list of size {L}"
|
|
187
|
+
else:
|
|
188
|
+
return f"Histogram defined by {L} data lists"
|
|
189
|
+
|
|
190
|
+
def _render_on_subplot(self, subplot):
|
|
191
|
+
"""
|
|
192
|
+
Render this bar chart graphics primitive on a matplotlib subplot
|
|
193
|
+
object.
|
|
194
|
+
|
|
195
|
+
EXAMPLES:
|
|
196
|
+
|
|
197
|
+
This rendering happens implicitly when the following command
|
|
198
|
+
is executed::
|
|
199
|
+
|
|
200
|
+
sage: histogram([1,2,10]) # indirect doctest
|
|
201
|
+
Graphics object consisting of 1 graphics primitive
|
|
202
|
+
"""
|
|
203
|
+
options = self.options()
|
|
204
|
+
# check to see if a list of datasets
|
|
205
|
+
if not hasattr(self.datalist[0], '__contains__'):
|
|
206
|
+
subplot.hist(self.datalist, **options)
|
|
207
|
+
else:
|
|
208
|
+
subplot.hist(self.datalist.transpose(), **options)
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
@options(aspect_ratio='automatic', align='mid', weights=None, range=None, bins=10, edgecolor='black')
|
|
212
|
+
def histogram(datalist, **options):
|
|
213
|
+
"""
|
|
214
|
+
Compute and draw the histogram for list(s) of numerical data.
|
|
215
|
+
See examples for the many options; even more customization is
|
|
216
|
+
available using matplotlib directly.
|
|
217
|
+
|
|
218
|
+
INPUT:
|
|
219
|
+
|
|
220
|
+
- ``datalist`` -- list, or a list of lists, of numerical data
|
|
221
|
+
- ``align`` -- (default: ``'mid'``) how the bars align inside of each bin.
|
|
222
|
+
Acceptable values are ``'left'`` ``'right'`` or ``'mid'``
|
|
223
|
+
- ``alpha`` -- (float in [0,1], default: 1) The transparency of the plot
|
|
224
|
+
- ``bins`` -- the number of sections in which to divide the range. Also
|
|
225
|
+
can be a sequence of points within the range that create the
|
|
226
|
+
partition
|
|
227
|
+
- ``color`` -- the color of the face of the bars or list of colors if
|
|
228
|
+
multiple data sets are given
|
|
229
|
+
- ``cumulative`` -- boolean (default: ``False``); if True, then
|
|
230
|
+
a histogram is computed in which each bin gives the counts in that
|
|
231
|
+
bin plus all bins for smaller values. Negative values give
|
|
232
|
+
a reversed direction of accumulation
|
|
233
|
+
- ``edgecolor`` -- the color of the border of each bar
|
|
234
|
+
- ``fill`` -- boolean (default: ``True``); whether to fill the bars
|
|
235
|
+
- ``hatch`` -- (default: ``None``) symbol to fill the bars with; one of
|
|
236
|
+
"/", "\\", "|", "-", "+", "x", "o", "O", ".", "*", "" (or None)
|
|
237
|
+
- ``hue`` -- the color of the bars given as a hue. See
|
|
238
|
+
:mod:`~sage.plot.colors.hue` for more information on the hue
|
|
239
|
+
- ``label`` -- string label for each data list given
|
|
240
|
+
- ``linewidth`` -- (float) width of the lines defining the bars
|
|
241
|
+
- ``linestyle`` -- (default: ``'solid'``) style of the line. One of 'solid'
|
|
242
|
+
or '-', 'dashed' or '--', 'dotted' or ':', 'dashdot' or '-.'
|
|
243
|
+
- ``density`` -- boolean (default: ``False``); if True, the result is the
|
|
244
|
+
value of the probability density function at the bin, normalized such
|
|
245
|
+
that the integral over the range is 1.
|
|
246
|
+
- ``range`` -- list [min, max] which define the range of the
|
|
247
|
+
histogram. Values outside of this range are treated as outliers and
|
|
248
|
+
omitted from counts
|
|
249
|
+
- ``rwidth`` -- (float in [0,1], default: 1) The relative width of the bars
|
|
250
|
+
as a fraction of the bin width
|
|
251
|
+
- ``stacked`` -- boolean (default: ``False``); if True, multiple data are
|
|
252
|
+
stacked on top of each other
|
|
253
|
+
- ``weights`` -- (list) A sequence of weights the same length as the data
|
|
254
|
+
list. If supplied, then each value contributes its associated weight
|
|
255
|
+
to the bin count
|
|
256
|
+
- ``zorder`` -- integer; the layer level at which to draw the histogram
|
|
257
|
+
|
|
258
|
+
.. NOTE::
|
|
259
|
+
|
|
260
|
+
The ``weights`` option works only with a single list. List of lists
|
|
261
|
+
representing multiple data are not supported.
|
|
262
|
+
|
|
263
|
+
EXAMPLES:
|
|
264
|
+
|
|
265
|
+
A very basic histogram for four data points::
|
|
266
|
+
|
|
267
|
+
sage: histogram([1, 2, 3, 4], bins=2)
|
|
268
|
+
Graphics object consisting of 1 graphics primitive
|
|
269
|
+
|
|
270
|
+
.. PLOT::
|
|
271
|
+
|
|
272
|
+
sphinx_plot(histogram([1, 2, 3, 4], bins=2))
|
|
273
|
+
|
|
274
|
+
We can see how the histogram compares to various distributions.
|
|
275
|
+
Note the use of the ``density`` keyword to guarantee the plot
|
|
276
|
+
looks like the probability density function::
|
|
277
|
+
|
|
278
|
+
sage: nv = normalvariate
|
|
279
|
+
sage: H = histogram([nv(0, 1) for _ in range(1000)], bins=20, density=True, range=[-5, 5])
|
|
280
|
+
sage: P = plot(1/sqrt(2*pi)*e^(-x^2/2), (x, -5, 5), color='red', linestyle='--') # needs sage.symbolic
|
|
281
|
+
sage: H + P # needs sage.symbolic
|
|
282
|
+
Graphics object consisting of 2 graphics primitives
|
|
283
|
+
|
|
284
|
+
.. PLOT::
|
|
285
|
+
|
|
286
|
+
nv = normalvariate
|
|
287
|
+
H = histogram([nv(0, 1) for _ in range(1000)], bins=20, density=True, range=[-5,5 ])
|
|
288
|
+
P = plot(1/sqrt(2*pi)*e**(-x**2/2), (x, -5, 5), color='red', linestyle='--')
|
|
289
|
+
sphinx_plot(H+P)
|
|
290
|
+
|
|
291
|
+
There are many options one can use with histograms. Some of these
|
|
292
|
+
control the presentation of the data, even if it is boring::
|
|
293
|
+
|
|
294
|
+
sage: histogram(list(range(100)), color=(1,0,0), label='mydata', rwidth=.5, align='right')
|
|
295
|
+
Graphics object consisting of 1 graphics primitive
|
|
296
|
+
|
|
297
|
+
.. PLOT::
|
|
298
|
+
|
|
299
|
+
sphinx_plot(histogram(list(range(100)), color=(1,0,0), label='mydata', rwidth=.5, align='right'))
|
|
300
|
+
|
|
301
|
+
This includes many usual matplotlib styling options::
|
|
302
|
+
|
|
303
|
+
sage: T = RealDistribution('lognormal', [0, 1])
|
|
304
|
+
sage: histogram( [T.get_random_element() for _ in range(100)], alpha=0.3, edgecolor='red', fill=False, linestyle='dashed', hatch='O', linewidth=5)
|
|
305
|
+
Graphics object consisting of 1 graphics primitive
|
|
306
|
+
|
|
307
|
+
.. PLOT::
|
|
308
|
+
|
|
309
|
+
T = RealDistribution('lognormal', [0, 1])
|
|
310
|
+
H = histogram( [T.get_random_element() for _ in range(100)], alpha=0.3, edgecolor='red', fill=False, linestyle='dashed', hatch='O', linewidth=5)
|
|
311
|
+
sphinx_plot(H)
|
|
312
|
+
|
|
313
|
+
::
|
|
314
|
+
|
|
315
|
+
sage: histogram( [T.get_random_element() for _ in range(100)],linestyle='-.')
|
|
316
|
+
Graphics object consisting of 1 graphics primitive
|
|
317
|
+
|
|
318
|
+
.. PLOT::
|
|
319
|
+
|
|
320
|
+
T = RealDistribution('lognormal', [0, 1])
|
|
321
|
+
sphinx_plot(histogram( [T.get_random_element() for _ in range(100)],linestyle='-.'))
|
|
322
|
+
|
|
323
|
+
We can do several data sets at once if desired::
|
|
324
|
+
|
|
325
|
+
sage: histogram([srange(0, 1, .1)*10, [nv(0, 1) for _ in range(100)]], color=['red', 'green'], bins=5)
|
|
326
|
+
Graphics object consisting of 1 graphics primitive
|
|
327
|
+
|
|
328
|
+
.. PLOT::
|
|
329
|
+
|
|
330
|
+
nv = normalvariate
|
|
331
|
+
sphinx_plot(histogram([srange(0, 1, .1)*10, [nv(0, 1) for _ in range(100)]], color=['red', 'green'], bins=5))
|
|
332
|
+
|
|
333
|
+
We have the option of stacking the data sets too::
|
|
334
|
+
|
|
335
|
+
sage: histogram([[1, 1, 1, 1, 2, 2, 2, 3, 3, 3], [4, 4, 4, 4, 3, 3, 3, 2, 2, 2] ], stacked=True, color=['blue', 'red'])
|
|
336
|
+
Graphics object consisting of 1 graphics primitive
|
|
337
|
+
|
|
338
|
+
.. PLOT::
|
|
339
|
+
|
|
340
|
+
sphinx_plot(histogram([[1, 1, 1, 1, 2, 2, 2, 3, 3, 3], [4, 4, 4, 4, 3, 3, 3, 2, 2, 2] ], stacked=True, color=['blue', 'red']))
|
|
341
|
+
|
|
342
|
+
It is possible to use weights with the histogram as well::
|
|
343
|
+
|
|
344
|
+
sage: histogram(list(range(10)), bins=3, weights=[1, 2, 3, 4, 5, 5, 4, 3, 2, 1])
|
|
345
|
+
Graphics object consisting of 1 graphics primitive
|
|
346
|
+
|
|
347
|
+
.. PLOT::
|
|
348
|
+
|
|
349
|
+
sphinx_plot(histogram(list(range(10)), bins=3, weights=[1, 2, 3, 4, 5, 5, 4, 3, 2, 1]))
|
|
350
|
+
"""
|
|
351
|
+
g = Graphics()
|
|
352
|
+
g._set_extra_kwds(Graphics._extract_kwds_for_show(options))
|
|
353
|
+
g.add_primitive(Histogram(datalist, options=options))
|
|
354
|
+
return g
|