passagemath-plot 10.6.31rc3__cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.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.

Files changed (82) hide show
  1. passagemath_plot-10.6.31rc3.dist-info/METADATA +172 -0
  2. passagemath_plot-10.6.31rc3.dist-info/RECORD +82 -0
  3. passagemath_plot-10.6.31rc3.dist-info/WHEEL +6 -0
  4. passagemath_plot-10.6.31rc3.dist-info/top_level.txt +2 -0
  5. passagemath_plot.libs/libgfortran-83c28eba.so.5.0.0 +0 -0
  6. passagemath_plot.libs/libgsl-cda90e79.so.28.0.0 +0 -0
  7. passagemath_plot.libs/libopenblasp-r0-6dcb67f9.3.29.so +0 -0
  8. passagemath_plot.libs/libquadmath-2284e583.so.0.0.0 +0 -0
  9. sage/all__sagemath_plot.py +15 -0
  10. sage/ext_data/threejs/animation.css +195 -0
  11. sage/ext_data/threejs/animation.html +85 -0
  12. sage/ext_data/threejs/animation.js +273 -0
  13. sage/ext_data/threejs/fat_lines.js +48 -0
  14. sage/ext_data/threejs/threejs-version.txt +1 -0
  15. sage/ext_data/threejs/threejs_template.html +597 -0
  16. sage/interfaces/all__sagemath_plot.py +1 -0
  17. sage/interfaces/gnuplot.py +196 -0
  18. sage/interfaces/jmoldata.py +208 -0
  19. sage/interfaces/povray.py +56 -0
  20. sage/plot/all.py +42 -0
  21. sage/plot/animate.py +1796 -0
  22. sage/plot/arc.py +504 -0
  23. sage/plot/arrow.py +671 -0
  24. sage/plot/bar_chart.py +205 -0
  25. sage/plot/bezier_path.py +400 -0
  26. sage/plot/circle.py +435 -0
  27. sage/plot/colors.py +1606 -0
  28. sage/plot/complex_plot.cpython-314-x86_64-linux-gnu.so +0 -0
  29. sage/plot/complex_plot.pyx +1446 -0
  30. sage/plot/contour_plot.py +1792 -0
  31. sage/plot/density_plot.py +318 -0
  32. sage/plot/disk.py +373 -0
  33. sage/plot/ellipse.py +375 -0
  34. sage/plot/graphics.py +3580 -0
  35. sage/plot/histogram.py +354 -0
  36. sage/plot/hyperbolic_arc.py +404 -0
  37. sage/plot/hyperbolic_polygon.py +416 -0
  38. sage/plot/hyperbolic_regular_polygon.py +296 -0
  39. sage/plot/line.py +626 -0
  40. sage/plot/matrix_plot.py +629 -0
  41. sage/plot/misc.py +509 -0
  42. sage/plot/multigraphics.py +1294 -0
  43. sage/plot/plot.py +4183 -0
  44. sage/plot/plot3d/all.py +23 -0
  45. sage/plot/plot3d/base.cpython-314-x86_64-linux-gnu.so +0 -0
  46. sage/plot/plot3d/base.pxd +12 -0
  47. sage/plot/plot3d/base.pyx +3378 -0
  48. sage/plot/plot3d/implicit_plot3d.py +659 -0
  49. sage/plot/plot3d/implicit_surface.cpython-314-x86_64-linux-gnu.so +0 -0
  50. sage/plot/plot3d/implicit_surface.pyx +1453 -0
  51. sage/plot/plot3d/index_face_set.cpython-314-x86_64-linux-gnu.so +0 -0
  52. sage/plot/plot3d/index_face_set.pxd +32 -0
  53. sage/plot/plot3d/index_face_set.pyx +1873 -0
  54. sage/plot/plot3d/introduction.py +131 -0
  55. sage/plot/plot3d/list_plot3d.py +649 -0
  56. sage/plot/plot3d/parametric_plot3d.py +1130 -0
  57. sage/plot/plot3d/parametric_surface.cpython-314-x86_64-linux-gnu.so +0 -0
  58. sage/plot/plot3d/parametric_surface.pxd +12 -0
  59. sage/plot/plot3d/parametric_surface.pyx +893 -0
  60. sage/plot/plot3d/platonic.py +601 -0
  61. sage/plot/plot3d/plot3d.py +1442 -0
  62. sage/plot/plot3d/plot_field3d.py +162 -0
  63. sage/plot/plot3d/point_c.pxi +148 -0
  64. sage/plot/plot3d/revolution_plot3d.py +309 -0
  65. sage/plot/plot3d/shapes.cpython-314-x86_64-linux-gnu.so +0 -0
  66. sage/plot/plot3d/shapes.pxd +22 -0
  67. sage/plot/plot3d/shapes.pyx +1382 -0
  68. sage/plot/plot3d/shapes2.py +1512 -0
  69. sage/plot/plot3d/tachyon.py +1779 -0
  70. sage/plot/plot3d/texture.py +453 -0
  71. sage/plot/plot3d/transform.cpython-314-x86_64-linux-gnu.so +0 -0
  72. sage/plot/plot3d/transform.pxd +21 -0
  73. sage/plot/plot3d/transform.pyx +268 -0
  74. sage/plot/plot3d/tri_plot.py +589 -0
  75. sage/plot/plot_field.py +362 -0
  76. sage/plot/point.py +624 -0
  77. sage/plot/polygon.py +562 -0
  78. sage/plot/primitive.py +249 -0
  79. sage/plot/scatter_plot.py +199 -0
  80. sage/plot/step.py +85 -0
  81. sage/plot/streamline_plot.py +328 -0
  82. sage/plot/text.py +432 -0
sage/plot/bar_chart.py ADDED
@@ -0,0 +1,205 @@
1
+ # sage_setup: distribution = sagemath-plot
2
+ """
3
+ Bar charts
4
+ """
5
+
6
+ # *****************************************************************************
7
+ # Copyright (C) 2006 Alex Clemesha <clemesha@gmail.com>,
8
+ # William Stein <wstein@gmail.com>,
9
+ # 2008 Mike Hansen <mhansen@gmail.com>,
10
+ #
11
+ # Distributed under the terms of the GNU General Public License (GPL)
12
+ #
13
+ # This code is distributed in the hope that it will be useful,
14
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
+ # General Public License for more details.
17
+ #
18
+ # The full text of the GPL is available at:
19
+ #
20
+ # http://www.gnu.org/licenses/
21
+ # *****************************************************************************
22
+ from sage.plot.primitive import GraphicPrimitive
23
+ from sage.plot.plot import minmax_data
24
+ from sage.plot.graphics import Graphics
25
+ from sage.misc.decorators import options, rename_keyword
26
+
27
+ # TODO: make bar_chart more general
28
+
29
+
30
+ class BarChart(GraphicPrimitive):
31
+ """
32
+ Graphics primitive that represents a bar chart.
33
+
34
+ EXAMPLES::
35
+
36
+ sage: from sage.plot.bar_chart import BarChart
37
+ sage: g = BarChart(list(range(4)), [1,3,2,0], {}); g
38
+ BarChart defined by a 4 datalist
39
+ sage: type(g)
40
+ <class 'sage.plot.bar_chart.BarChart'>
41
+ """
42
+ def __init__(self, ind, datalist, options):
43
+ """
44
+ Initialize a ``BarChart`` primitive.
45
+
46
+ EXAMPLES::
47
+
48
+ sage: from sage.plot.bar_chart import BarChart
49
+ sage: BarChart(list(range(3)), [10,3,5], {'width':0.7})
50
+ BarChart defined by a 3 datalist
51
+ """
52
+ self.datalist = datalist
53
+ self.ind = ind
54
+ GraphicPrimitive.__init__(self, options)
55
+
56
+ def get_minmax_data(self):
57
+ """
58
+ Return a dictionary with the bounding box data.
59
+
60
+ EXAMPLES::
61
+
62
+ sage: b = bar_chart([-2.3,5,-6,12])
63
+ sage: d = b.get_minmax_data()
64
+ sage: d['xmin']
65
+ 0
66
+ sage: d['xmax']
67
+ 4
68
+ """
69
+ return minmax_data([0, len(self.datalist)], self.datalist, dict=True)
70
+
71
+ def _allowed_options(self):
72
+ """
73
+ Return the allowed options with descriptions for this graphics
74
+ primitive. This is used in displaying an error message when the
75
+ user gives an option that doesn't make sense.
76
+
77
+ EXAMPLES::
78
+
79
+ sage: from sage.plot.bar_chart import BarChart
80
+ sage: g = BarChart(list(range(4)), [1,3,2,0], {})
81
+ sage: list(sorted(g._allowed_options().items()))
82
+ [('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')]
83
+ """
84
+ return {'rgbcolor': 'The color as an RGB tuple.',
85
+ 'hue': 'The color given as a hue.',
86
+ 'legend_label': 'The label for this item in the legend.',
87
+ 'width': 'The width of the bars',
88
+ 'zorder': 'The layer level in which to draw'}
89
+
90
+ def _repr_(self):
91
+ """
92
+ Return text representation of this bar chart graphics primitive.
93
+
94
+ EXAMPLES::
95
+
96
+ sage: from sage.plot.bar_chart import BarChart
97
+ sage: g = BarChart(list(range(4)), [1,3,2,0], {})
98
+ sage: g._repr_()
99
+ 'BarChart defined by a 4 datalist'
100
+ """
101
+ return "BarChart defined by a %s datalist" % (len(self.datalist))
102
+
103
+ def _render_on_subplot(self, subplot):
104
+ """
105
+ Render this bar chart graphics primitive on a matplotlib subplot
106
+ object.
107
+
108
+ EXAMPLES:
109
+
110
+ This rendering happens implicitly when the following command
111
+ is executed::
112
+
113
+ sage: bar_chart([1,2,10])
114
+ Graphics object consisting of 1 graphics primitive
115
+ """
116
+ options = self.options()
117
+ color = options['rgbcolor']
118
+ width = float(options['width'])
119
+ # it is critical to make NumPy arrays of type float below,
120
+ # or bar will go boom:
121
+ import numpy
122
+ ind = numpy.array(self.ind, dtype=float)
123
+ datalist = numpy.array(self.datalist, dtype=float)
124
+ subplot.bar(ind, datalist, color=color, width=width, label=options['legend_label'])
125
+
126
+
127
+ @rename_keyword(color='rgbcolor')
128
+ @options(width=0.5, rgbcolor=(0, 0, 1), legend_label=None, aspect_ratio='automatic')
129
+ def bar_chart(datalist, **options):
130
+ """
131
+ A bar chart of (currently) one list of numerical data.
132
+ Support for more data lists in progress.
133
+
134
+ EXAMPLES:
135
+
136
+ A bar_chart with blue bars::
137
+
138
+ sage: bar_chart([1,2,3,4])
139
+ Graphics object consisting of 1 graphics primitive
140
+
141
+ .. PLOT::
142
+
143
+ sphinx_plot(bar_chart([1,2,3,4]))
144
+
145
+ A bar_chart with thinner bars::
146
+
147
+ sage: bar_chart([x^2 for x in range(1,20)], width=0.2)
148
+ Graphics object consisting of 1 graphics primitive
149
+
150
+ .. PLOT::
151
+
152
+ sphinx_plot(bar_chart([x**2 for x in range(1,20)], width=0.2))
153
+
154
+ A bar_chart with negative values and red bars::
155
+
156
+ sage: bar_chart([-3,5,-6,11], rgbcolor=(1,0,0))
157
+ Graphics object consisting of 1 graphics primitive
158
+
159
+ .. PLOT::
160
+
161
+ sphinx_plot(bar_chart([-3,5,-6,11], rgbcolor=(1,0,0)))
162
+
163
+ A bar chart with a legend (it's possible, not necessarily useful)::
164
+
165
+ sage: bar_chart([-1,1,-1,1], legend_label='wave')
166
+ Graphics object consisting of 1 graphics primitive
167
+
168
+ .. PLOT::
169
+
170
+ sphinx_plot(bar_chart([-1,1,-1,1], legend_label='wave'))
171
+
172
+ Extra options will get passed on to show(), as long as they are valid::
173
+
174
+ sage: bar_chart([-2,8,-7,3], rgbcolor=(1,0,0), axes=False)
175
+ Graphics object consisting of 1 graphics primitive
176
+ sage: bar_chart([-2,8,-7,3], rgbcolor=(1,0,0)).show(axes=False) # These are equivalent
177
+
178
+ .. PLOT::
179
+
180
+ sphinx_plot(bar_chart([-2,8,-7,3], rgbcolor=(1,0,0), axes=False))
181
+ """
182
+ dl = len(datalist)
183
+ if dl == 3:
184
+ datalist = datalist + [0]
185
+ # bardata = []
186
+ # cnt = 1
187
+ # for pnts in datalist:
188
+ # ind = [i+cnt/dl for i in range(len(pnts))]
189
+ # bardata.append([ind, pnts, xrange, yrange])
190
+ # cnt += 1
191
+
192
+ g = Graphics()
193
+ g._set_extra_kwds(Graphics._extract_kwds_for_show(options))
194
+ # TODO: improve below for multiple data sets!
195
+ # cnt = 1
196
+ # for ind, pnts, xrange, yrange in bardata:
197
+ # options={'rgbcolor':hue(cnt/dl),'width':0.5/dl}
198
+ # g._bar_chart(ind, pnts, xrange, yrange, options=options)
199
+ # cnt += 1
200
+ # else:
201
+ ind = list(range(len(datalist)))
202
+ g.add_primitive(BarChart(ind, datalist, options=options))
203
+ if options['legend_label']:
204
+ g.legend(True)
205
+ return g
@@ -0,0 +1,400 @@
1
+ # sage_setup: distribution = sagemath-plot
2
+ r"""
3
+ Bezier paths
4
+ """
5
+ #*****************************************************************************
6
+ # Copyright (C) 2006 Alex Clemesha <clemesha@gmail.com>,
7
+ # William Stein <wstein@gmail.com>,
8
+ # 2008 Mike Hansen <mhansen@gmail.com>,
9
+ # 2009 Emily Kirkman
10
+ #
11
+ # Distributed under the terms of the GNU General Public License (GPL)
12
+ #
13
+ # This code is distributed in the hope that it will be useful,
14
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
+ # General Public License for more details.
17
+ #
18
+ # The full text of the GPL is available at:
19
+ #
20
+ # http://www.gnu.org/licenses/
21
+ #*****************************************************************************
22
+ from sage.plot.primitive import GraphicPrimitive_xydata
23
+ from sage.misc.decorators import options, rename_keyword
24
+ from sage.plot.colors import to_mpl_color
25
+
26
+
27
+ class BezierPath(GraphicPrimitive_xydata):
28
+ """
29
+ Path of Bezier Curves graphics primitive.
30
+
31
+ The input to this constructor is a list of curves, each a list of points,
32
+ along which to create the curves, along with a dict of any options passed.
33
+
34
+ EXAMPLES::
35
+
36
+ sage: from sage.plot.bezier_path import BezierPath
37
+ sage: BezierPath([[(0,0), (.5,.5),(1,0)],[(.5,1),(0,0)]], {'linestyle':'dashed'})
38
+ Bezier path from (0.0, 0.0) to (0.0, 0.0)
39
+
40
+ We use :func:`bezier_path` to actually plot Bezier curves::
41
+
42
+ sage: bezier_path([[(0,0),(.5,.5),(1,0)],[(.5,1),(0,0)]], linestyle='dashed')
43
+ Graphics object consisting of 1 graphics primitive
44
+
45
+ .. PLOT::
46
+
47
+ P = bezier_path([[(0,0),(.5,.5),(1,0)],[(.5,1),(0,0)]], linestyle='dashed')
48
+ sphinx_plot(P)
49
+ """
50
+ def __init__(self, path, options):
51
+ """
52
+ Return a graphics primitive of a path of Bezier curves.
53
+
54
+ EXAMPLES::
55
+
56
+ sage: from sage.plot.bezier_path import BezierPath
57
+ sage: BezierPath([[(0,0),(.5,.5),(1,0)],[(.5,1),(0,0)]], {'linestyle':'dashed'})
58
+ Bezier path from (0.0, 0.0) to (0.0, 0.0)
59
+
60
+ sage: BezierPath([[(0,0), (1,2), (3,6), (2,-1), (3,3)]], {})
61
+ Traceback (most recent call last):
62
+ ...
63
+ ValueError: invalid input for BezierPath
64
+
65
+ TESTS:
66
+
67
+ Check :issue:`31646`::
68
+
69
+ sage: from sage.plot.bezier_path import BezierPath
70
+ sage: p2d = [[(3,0),(4,1),(2,1),(3,0)], [(2,2),(3,1),(2,1)]]
71
+ sage: P = BezierPath(p2d, {})
72
+ sage: P.path
73
+ [array([[3., 0.], [4., 1.], [2., 1.], [3., 0.]]),
74
+ array([[2., 2.], [3., 1.], [2., 1.]])]
75
+ """
76
+ import numpy as np
77
+
78
+ self.path = [np.array(l, float) for l in path]
79
+
80
+ # In order to feed later to matplotlib.path.Path we convert in
81
+ # the following form
82
+ # - vertices: an Nx2 float array of vertices
83
+ # - codes: an N-length uint8 array of vertex types, or None
84
+ # where each code could be MOVETO (=1), LINETO (=2), CURVE3 (=3), CURVE4 (=4)
85
+ self.vertices = np.concatenate(self.path)
86
+ N, _ = self.vertices.shape
87
+ codes = np.zeros((N,), np.uint8)
88
+ k = 0
89
+ for i, curve in enumerate(self.path):
90
+ code = len(curve) + (i > 0)
91
+ if code < 2 or code > 4:
92
+ raise ValueError('invalid input for BezierPath')
93
+ codes[k:k+len(curve)] = code
94
+ k += len(curve)
95
+ codes[0] = 1 # MOVETO
96
+ self.codes = codes
97
+ GraphicPrimitive_xydata.__init__(self, options)
98
+
99
+ def _allowed_options(self):
100
+ """
101
+ Return a dict of allowed options for ``bezier_path``.
102
+
103
+ EXAMPLES::
104
+
105
+ sage: from sage.plot.bezier_path import BezierPath
106
+ sage: list(sorted(BezierPath([[[-1,2], [14,2.3], [17,4]]], {})._allowed_options().items()))
107
+ [('alpha', 'How transparent the line is.'),
108
+ ('fill', 'Whether or not to fill the polygon.'),
109
+ ('linestyle',
110
+ "The style of the line, which is one of 'dashed', 'dotted', 'solid',
111
+ 'dashdot', or '--', ':', '-', '-.', respectively."),
112
+ ('rgbcolor', 'The color as an RGB tuple.'),
113
+ ('thickness', 'How thick the border of the polygon is.'),
114
+ ('zorder', 'The layer level in which to draw')]
115
+ """
116
+ return {'alpha': 'How transparent the line is.',
117
+ 'fill': 'Whether or not to fill the polygon.',
118
+ 'thickness': 'How thick the border of the polygon is.',
119
+ 'rgbcolor': 'The color as an RGB tuple.',
120
+ 'zorder': 'The layer level in which to draw',
121
+ 'linestyle': "The style of the line, which is one of 'dashed',"
122
+ " 'dotted', 'solid', 'dashdot', or '--', ':', '-', '-.',"
123
+ " respectively."}
124
+
125
+ def _plot3d_options(self, options=None):
126
+ """
127
+ Update ``BezierPath`` options to those allowed by 3D implementation.
128
+
129
+ EXAMPLES::
130
+
131
+ sage: from sage.plot.bezier_path import BezierPath
132
+ sage: B = BezierPath([[(0,0),(.5,.5),(1,0)],[(.5,1),(0,0)]], {'linestyle':'dashed'})
133
+ sage: B._plot3d_options()
134
+ Traceback (most recent call last):
135
+ ...
136
+ NotImplementedError: invalid 3d line style: 'dashed'
137
+ sage: B = BezierPath([[(0,0),(.5,.5),(1,0)],[(.5,1),(0,0)]], {'fill':False, 'thickness':2})
138
+ sage: B._plot3d_options()
139
+ {'thickness': 2}
140
+ """
141
+ if options is None:
142
+ options = dict(self.options())
143
+ options_3d = {}
144
+ if 'thickness' in options:
145
+ options_3d['thickness'] = options['thickness']
146
+ del options['thickness']
147
+ if 'fill' in options:
148
+ if options['fill']:
149
+ raise NotImplementedError("invalid 3d fill style; must set fill to False")
150
+ del options['fill']
151
+ if 'linestyle' in options:
152
+ if options['linestyle'] not in ('solid', '-'):
153
+ raise NotImplementedError("invalid 3d line style: '%s'" %
154
+ (options['linestyle']))
155
+ del options['linestyle']
156
+ options_3d.update(GraphicPrimitive_xydata._plot3d_options(self, options))
157
+ return options_3d
158
+
159
+ def plot3d(self, z=0, **kwds):
160
+ """
161
+ Return a 3D plot (Jmol) of the Bezier path. Since a ``BezierPath``
162
+ primitive contains only `x,y` coordinates, the path will be drawn in
163
+ some plane (default: `z=0`). To create a Bezier path with nonzero
164
+ (and nonidentical) `z` coordinates in the path and control points, use
165
+ the function :func:`~sage.plot.plot3d.shapes2.bezier3d` instead of
166
+ :func:`bezier_path`.
167
+
168
+ EXAMPLES::
169
+
170
+ sage: b = bezier_path([[(0,0),(0,1),(1,0)]])
171
+ sage: A = b.plot3d() # needs sage.symbolic
172
+ sage: B = b.plot3d(z=2) # needs sage.symbolic
173
+ sage: A + B # needs sage.symbolic
174
+ Graphics3d Object
175
+
176
+ .. PLOT::
177
+
178
+ b = bezier_path([[(0,0),(0,1),(1,0)]])
179
+ A = b.plot3d()
180
+ B = b.plot3d(z=2)
181
+ sphinx_plot(A + B)
182
+
183
+ ::
184
+
185
+ sage: bezier3d([[(0,0,0),(1,0,0),(0,1,0),(0,1,1)]]) # needs sage.symbolic
186
+ Graphics3d Object
187
+
188
+ .. PLOT::
189
+
190
+ sphinx_plot(bezier3d([[(0,0,0),(1,0,0),(0,1,0),(0,1,1)]]))
191
+ """
192
+ from sage.plot.plot3d.shapes2 import bezier3d
193
+ options = self._plot3d_options()
194
+ options.update(kwds)
195
+ return bezier3d([[(x,y,0) for x,y in self.path[i]] for i in range(len(self.path))], **options)
196
+
197
+ def _repr_(self):
198
+ """
199
+ Return text representation of this Bezier path graphics primitive.
200
+
201
+ EXAMPLES::
202
+
203
+ sage: from sage.plot.bezier_path import BezierPath
204
+ sage: B = BezierPath([[(0,0),(.5,.5),(1,0)],[(.5,1),(0,0)]], {'linestyle':'dashed'})
205
+ sage: B._repr_()
206
+ 'Bezier path from (0.0, 0.0) to (0.0, 0.0)'
207
+ """
208
+ x0, y0 = self.vertices[0]
209
+ x1, y1 = self.vertices[-1]
210
+ return f"Bezier path from ({x0}, {y0}) to ({x1}, {y1})"
211
+
212
+ def _render_on_subplot(self, subplot):
213
+ """
214
+ Render this Bezier path in a subplot. This is the key function that
215
+ defines how this Bezier path graphics primitive is rendered in matplotlib's
216
+ library.
217
+
218
+ TESTS::
219
+
220
+ sage: bezier_path([[(0,1),(.5,0),(1,1)]])
221
+ Graphics object consisting of 1 graphics primitive
222
+
223
+ ::
224
+
225
+ sage: bezier_path([[(0,1),(.5,0),(1,1),(-3,5)]])
226
+ Graphics object consisting of 1 graphics primitive
227
+ """
228
+ from matplotlib.patches import PathPatch
229
+ from matplotlib.path import Path
230
+ from sage.plot.misc import get_matplotlib_linestyle
231
+
232
+ options = dict(self.options())
233
+
234
+ del options['alpha']
235
+ del options['thickness']
236
+ del options['rgbcolor']
237
+ del options['zorder']
238
+ del options['fill']
239
+ del options['linestyle']
240
+
241
+ bpath = Path(self.vertices, self.codes)
242
+ bpatch = PathPatch(bpath, **options)
243
+ options = self.options()
244
+ bpatch.set_linewidth(float(options['thickness']))
245
+ bpatch.set_fill(options['fill'])
246
+ bpatch.set_zorder(options['zorder'])
247
+ a = float(options['alpha'])
248
+ bpatch.set_alpha(a)
249
+ c = to_mpl_color(options['rgbcolor'])
250
+ bpatch.set_edgecolor(c)
251
+ bpatch.set_facecolor(c)
252
+ bpatch.set_linestyle(get_matplotlib_linestyle(options['linestyle'], return_type='long'))
253
+ subplot.add_patch(bpatch)
254
+
255
+ def get_minmax_data(self):
256
+ """
257
+ Return a dictionary with the bounding box data.
258
+
259
+ EXAMPLES::
260
+
261
+ sage: b = bezier_path([[(0,0),(.5,.5),(1,0)],[(.5,1),(0,0)]])
262
+ sage: d = b.get_minmax_data()
263
+ sage: d['xmin']
264
+ np.float64(0.0)
265
+ sage: d['xmax']
266
+ np.float64(1.0)
267
+ """
268
+ return {'xmin': self.vertices[:,0].min(),
269
+ 'xmax': self.vertices[:,0].max(),
270
+ 'ymin': self.vertices[:,1].min(),
271
+ 'ymax': self.vertices[:,1].max()}
272
+
273
+
274
+ @rename_keyword(color='rgbcolor')
275
+ @options(alpha=1, fill=False, thickness=1, rgbcolor=(0,0,0), zorder=2, linestyle='solid')
276
+ def bezier_path(path, **options):
277
+ """
278
+ Return a Graphics object of a Bezier path corresponding to the
279
+ path parameter. The path is a list of curves, and each curve is
280
+ a list of points. Each point is a tuple ``(x,y)``.
281
+
282
+ The first curve contains the endpoints as the first and last point
283
+ in the list. All other curves assume a starting point given by the
284
+ last entry in the preceding list, and take the last point in the list
285
+ as their opposite endpoint. A curve can have 0, 1 or 2 control points
286
+ listed between the endpoints. In the input example for path below,
287
+ the first and second curves have 2 control points, the third has one,
288
+ and the fourth has no control points:
289
+
290
+ path = [[p1, c1, c2, p2], [c3, c4, p3], [c5, p4], [p5], ...]
291
+
292
+ In the case of no control points, a straight line will be drawn
293
+ between the two endpoints. If one control point is supplied, then
294
+ the curve at each of the endpoints will be tangent to the line from
295
+ that endpoint to the control point. Similarly, in the case of two
296
+ control points, at each endpoint the curve will be tangent to the line
297
+ connecting that endpoint with the control point immediately after or
298
+ immediately preceding it in the list.
299
+
300
+ .. PLOT::
301
+
302
+ p1 = (0,0)
303
+ c1 = (1,1)
304
+ c2 = (1.5,0.5)
305
+ p2 = (4,-1)
306
+ c3 = (3.5,0)
307
+ c4 = (2,1)
308
+ p3 = (0,2)
309
+ c5 = (0.5,3)
310
+ p4 = (1.5,2)
311
+ p5 = (0,4)
312
+ path = [[p1, c1, c2, p2], [c3, c4, p3], [c5, p4], [p5]]
313
+ P = bezier_path(path)
314
+ P += line([p1,c1], color='red', linestyle='dashed')
315
+ P += line([p2,c2], color='red', linestyle='dashed')
316
+ P += line([p2,c3], color='red', linestyle='dashed')
317
+ P += line([p3,c4], color='red', linestyle='dashed')
318
+ P += line([p3,c5], color='red', linestyle='dashed')
319
+ P += text("c1", c1, horizontal_alignment='left')
320
+ P += text("c2", c2, horizontal_alignment='right')
321
+ P += text("c3", c3, horizontal_alignment='left', vertical_alignment='bottom')
322
+ P += text("c4", c4, horizontal_alignment='left')
323
+ P += text("c5", c5, horizontal_alignment='left')
324
+ P += text("p1", p1, horizontal_alignment='left', vertical_alignment='top')
325
+ P += text("p2", p2, horizontal_alignment='left')
326
+ P += text("p3", p3, horizontal_alignment='right', vertical_alignment='top')
327
+ P += text("p4", p4, horizontal_alignment='left')
328
+ P += text("p5", p5, horizontal_alignment='left', vertical_alignment='bottom')
329
+ P += point([c1, c2, c3, c4, c5])
330
+ sphinx_plot(P)
331
+
332
+ So in our example above, the curve between p1 and p2 is tangent to the
333
+ line through p1 and c1 at p1, and tangent to the line through p2 and c2
334
+ at p2. Similarly, the curve between p2 and p3 is tangent to line(p2,c3)
335
+ at p2 and tangent to line(p3,c4) at p3. Curve(p3,p4) is tangent to
336
+ line(p3,c5) at p3 and tangent to line(p4,c5) at p4. Curve(p4,p5) is a
337
+ straight line.
338
+
339
+ INPUT:
340
+
341
+ - ``path`` -- list of lists of tuples (see above)
342
+ - ``alpha`` -- (default: 1)
343
+ - ``fill`` -- (default: ``False``)
344
+ - ``thickness`` -- (default: 1)
345
+ - ``linestyle`` -- (default: ``'solid'``) the style of the line, which is one
346
+ of ``'dashed'``, ``'dotted'``, ``'solid'``, ``'dashdot'``, or ``'--'``,
347
+ ``':'``, ``'-'``, ``'-.'``, respectively
348
+ - ``rgbcolor`` -- (default: (0,0,0))
349
+ - ``zorder`` -- the layer in which to draw
350
+
351
+ EXAMPLES::
352
+
353
+ sage: path = [[(0,0),(.5,.1),(.75,3),(1,0)],[(.5,1),(.5,0)],[(.2,.5)]]
354
+ sage: b = bezier_path(path, linestyle='dashed', rgbcolor='green')
355
+ sage: b
356
+ Graphics object consisting of 1 graphics primitive
357
+
358
+ .. PLOT::
359
+
360
+ path = [[(0,0),(.5,.1),(.75,3),(1,0)],[(.5,1),(.5,0)],[(.2,.5)]]
361
+ b = bezier_path(path, linestyle='dashed', rgbcolor='green')
362
+ sphinx_plot(b)
363
+
364
+ To construct a simple curve, create a list containing a single list::
365
+
366
+ sage: path = [[(0,0),(.5,1),(1,0)]]
367
+ sage: curve = bezier_path(path, linestyle='dashed', rgbcolor='green')
368
+ sage: curve
369
+ Graphics object consisting of 1 graphics primitive
370
+
371
+ .. PLOT::
372
+
373
+ path = [[(0,0),(.5,1),(1,0)]]
374
+ curve = bezier_path(path, linestyle='dashed', rgbcolor='green')
375
+ sphinx_plot(curve)
376
+
377
+ Extra options will get passed on to :meth:`~Graphics.show`, as long as they are valid::
378
+
379
+ sage: bezier_path([[(0,1),(.5,0),(1,1)]], fontsize=50)
380
+ Graphics object consisting of 1 graphics primitive
381
+ sage: bezier_path([[(0,1),(.5,0),(1,1)]]).show(fontsize=50) # These are equivalent
382
+
383
+ .. PLOT::
384
+
385
+ sphinx_plot(bezier_path([[(0,1),(.5,0),(1,1)]], fontsize=50))
386
+
387
+ TESTS:
388
+
389
+ We shouldn't modify our argument, :issue:`13822`::
390
+
391
+ sage: bp = [[(1,1),(2,3),(3,3)], [(4,4),(5,5)]]
392
+ sage: foo = bezier_path(bp)
393
+ sage: bp
394
+ [[(1, 1), (2, 3), (3, 3)], [(4, 4), (5, 5)]]
395
+ """
396
+ from sage.plot.all import Graphics
397
+ g = Graphics()
398
+ g._set_extra_kwds(g._extract_kwds_for_show(options))
399
+ g.add_primitive(BezierPath(path, options))
400
+ return g