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.
- passagemath_plot-10.6.31rc3.dist-info/METADATA +172 -0
- passagemath_plot-10.6.31rc3.dist-info/RECORD +82 -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-83c28eba.so.5.0.0 +0 -0
- passagemath_plot.libs/libgsl-cda90e79.so.28.0.0 +0 -0
- passagemath_plot.libs/libopenblasp-r0-6dcb67f9.3.29.so +0 -0
- passagemath_plot.libs/libquadmath-2284e583.so.0.0.0 +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-x86_64-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-x86_64-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-x86_64-linux-gnu.so +0 -0
- sage/plot/plot3d/implicit_surface.pyx +1453 -0
- sage/plot/plot3d/index_face_set.cpython-314-x86_64-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-x86_64-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-x86_64-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-x86_64-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
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
# sage_setup: distribution = sagemath-plot
|
|
2
|
+
r"""
|
|
3
|
+
Interface to the Gnuplot interpreter
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
# ****************************************************************************
|
|
7
|
+
# Copyright (C) 2005 William Stein <wstein@gmail.com>
|
|
8
|
+
#
|
|
9
|
+
# Distributed under the terms of the GNU General Public License (GPL)
|
|
10
|
+
#
|
|
11
|
+
# This code is distributed in the hope that it will be useful,
|
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
14
|
+
# General Public License for more details.
|
|
15
|
+
#
|
|
16
|
+
# The full text of the GPL is available at:
|
|
17
|
+
#
|
|
18
|
+
# https://www.gnu.org/licenses/
|
|
19
|
+
# ****************************************************************************
|
|
20
|
+
|
|
21
|
+
import os
|
|
22
|
+
import time
|
|
23
|
+
from sage.structure.sage_object import SageObject
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class Gnuplot(SageObject):
|
|
27
|
+
"""
|
|
28
|
+
Interface to the Gnuplot interpreter.
|
|
29
|
+
"""
|
|
30
|
+
def _quit_string(self):
|
|
31
|
+
return 'quit'
|
|
32
|
+
|
|
33
|
+
def gnuplot(self):
|
|
34
|
+
try:
|
|
35
|
+
return self._gnuplot
|
|
36
|
+
except AttributeError:
|
|
37
|
+
try:
|
|
38
|
+
import Gnuplot as GP
|
|
39
|
+
self._gnuplot = GP.Gnuplot()
|
|
40
|
+
return self._gnuplot
|
|
41
|
+
except ImportError:
|
|
42
|
+
raise RuntimeError("Install the gnuplotpy Python module.")
|
|
43
|
+
|
|
44
|
+
def __call__(self, line):
|
|
45
|
+
return self.gnuplot()(line)
|
|
46
|
+
|
|
47
|
+
def _eval_line(self, line, *args, **kwds):
|
|
48
|
+
self(line)
|
|
49
|
+
return ''
|
|
50
|
+
|
|
51
|
+
def _repr_(self):
|
|
52
|
+
"""
|
|
53
|
+
TESTS::
|
|
54
|
+
|
|
55
|
+
sage: gnuplot # indirect doctests
|
|
56
|
+
Interface to Gnuplot
|
|
57
|
+
"""
|
|
58
|
+
return "Interface to Gnuplot"
|
|
59
|
+
|
|
60
|
+
def plot(self, cmd, file=None, verbose=True, reset=True):
|
|
61
|
+
r"""
|
|
62
|
+
Draw the plot described by cmd, and possibly also save to an eps or
|
|
63
|
+
png file.
|
|
64
|
+
|
|
65
|
+
INPUT:
|
|
66
|
+
|
|
67
|
+
- ``cmd`` -- string
|
|
68
|
+
|
|
69
|
+
- ``file`` -- string (default: ``None``); if specified save
|
|
70
|
+
plot to given file, which may be either an eps (default) or png file
|
|
71
|
+
|
|
72
|
+
- ``verbose`` -- print some info
|
|
73
|
+
|
|
74
|
+
- ``reset`` -- true; reset gnuplot before making graph
|
|
75
|
+
|
|
76
|
+
OUTPUT: displays graph
|
|
77
|
+
|
|
78
|
+
.. NOTE::
|
|
79
|
+
|
|
80
|
+
Note that ``^`` s are replaced by ``**`` s before being passed to gnuplot.
|
|
81
|
+
"""
|
|
82
|
+
if reset:
|
|
83
|
+
self('reset')
|
|
84
|
+
self('set terminal x11')
|
|
85
|
+
cmd = cmd.replace('^', '**')
|
|
86
|
+
self(cmd)
|
|
87
|
+
if file is not None:
|
|
88
|
+
if file[-4:] == '.png':
|
|
89
|
+
self('set terminal png medium')
|
|
90
|
+
else:
|
|
91
|
+
if file[-4:] != '.eps':
|
|
92
|
+
file += '.eps'
|
|
93
|
+
self('set terminal postscript eps enhanced')
|
|
94
|
+
# self("set output '%s'"%file)
|
|
95
|
+
tmp = 'gnuplot_tmp%s' % file[-4:]
|
|
96
|
+
self("set output '%s'" % tmp)
|
|
97
|
+
print("Saving plot to %s" % file)
|
|
98
|
+
self(cmd)
|
|
99
|
+
time.sleep(0.1)
|
|
100
|
+
os.system('mv %s %s 2>/dev/null' % (tmp, file))
|
|
101
|
+
time.sleep(0.1)
|
|
102
|
+
self('set terminal x11')
|
|
103
|
+
|
|
104
|
+
def plot3d(self, f, xmin=-1, xmax=1, ymin=-1, ymax=1, zmin=-1, zmax=1,
|
|
105
|
+
title=None,
|
|
106
|
+
samples=25, isosamples=20, xlabel='x', ylabel='y',
|
|
107
|
+
interact=True):
|
|
108
|
+
if title is None:
|
|
109
|
+
title = str(f)
|
|
110
|
+
f = f.replace('^', '**')
|
|
111
|
+
cmd = """
|
|
112
|
+
set xlabel "%s"
|
|
113
|
+
set ylabel "%s"
|
|
114
|
+
set key top
|
|
115
|
+
set border 4095
|
|
116
|
+
set xrange [%s:%s]
|
|
117
|
+
set yrange [%s:%s]
|
|
118
|
+
set samples %s
|
|
119
|
+
set isosamples %s
|
|
120
|
+
|
|
121
|
+
set title "%s"
|
|
122
|
+
set pm3d; set palette
|
|
123
|
+
#show pm3d
|
|
124
|
+
#show palette
|
|
125
|
+
splot %s
|
|
126
|
+
""" % (xlabel, ylabel,
|
|
127
|
+
xmin, xmax, ymin, ymax, # zmin, zmax,
|
|
128
|
+
samples, isosamples,
|
|
129
|
+
title, f)
|
|
130
|
+
if interact:
|
|
131
|
+
self.interact(cmd)
|
|
132
|
+
else:
|
|
133
|
+
self(cmd)
|
|
134
|
+
|
|
135
|
+
def plot3d_parametric(self, f='cos(u)*(3 + v*cos(u/2)), sin(u)*(3 + v*cos(u/2)), v*sin(u/2)',
|
|
136
|
+
range1='[u=-pi:pi]',
|
|
137
|
+
range2='[v=-0.2:0.2]', samples=50, title=None,
|
|
138
|
+
interact=True):
|
|
139
|
+
r"""
|
|
140
|
+
Draw a parametric 3d surface and rotate it interactively.
|
|
141
|
+
|
|
142
|
+
INPUT:
|
|
143
|
+
|
|
144
|
+
- ``f`` -- string; a function of two variables, e.g.,
|
|
145
|
+
``'cos(u)\*(3 + v\*cos(u/2)), sin(u)\*(3 + v\*cos(u/2)), v\*sin(u/2)'``
|
|
146
|
+
|
|
147
|
+
- ``range1`` -- string; range of values for one
|
|
148
|
+
variable, e.g., ``'[u=-pi:pi]'``
|
|
149
|
+
|
|
150
|
+
- ``range2`` -- string; range of values for another
|
|
151
|
+
variable, e.g., ``'[v=-0.2:0.2]'``
|
|
152
|
+
|
|
153
|
+
- ``samples`` -- integer; number of sample points to use
|
|
154
|
+
|
|
155
|
+
- ``title`` -- string; title of the graph
|
|
156
|
+
|
|
157
|
+
EXAMPLES::
|
|
158
|
+
|
|
159
|
+
sage: gnuplot.plot3d_parametric('v^2*sin(u), v*cos(u), v*(1-v)') # optional - gnuplot, not tested (since something pops up)
|
|
160
|
+
"""
|
|
161
|
+
if title is None:
|
|
162
|
+
title = str(f)
|
|
163
|
+
cmd = """
|
|
164
|
+
set key top
|
|
165
|
+
set border 4095
|
|
166
|
+
set samples %s
|
|
167
|
+
|
|
168
|
+
set title "%s"
|
|
169
|
+
set pm3d; set palette; set parametric
|
|
170
|
+
splot %s %s %s
|
|
171
|
+
""" % (samples, title, range1, range2, f)
|
|
172
|
+
cmd = cmd.replace('^', '**')
|
|
173
|
+
if interact:
|
|
174
|
+
self.interact(cmd)
|
|
175
|
+
else:
|
|
176
|
+
self(cmd)
|
|
177
|
+
|
|
178
|
+
def interact(self, cmd):
|
|
179
|
+
import tempfile
|
|
180
|
+
with tempfile.NamedTemporaryFile(mode='w+t') as f:
|
|
181
|
+
f.write(cmd + '\n pause -1 "Press return to continue (no further rotation possible)"')
|
|
182
|
+
os.system(f'gnuplot -persist {f.name}')
|
|
183
|
+
|
|
184
|
+
def console(self):
|
|
185
|
+
gnuplot_console()
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
# An instance
|
|
189
|
+
gnuplot = Gnuplot()
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
def gnuplot_console():
|
|
193
|
+
from sage.repl.rich_output.display_manager import get_display_manager
|
|
194
|
+
if not get_display_manager().is_in_terminal():
|
|
195
|
+
raise RuntimeError('Can use the console only in the terminal. Try %%gnuplot magics instead.')
|
|
196
|
+
os.system('gnuplot')
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
# sage_setup: distribution = sagemath-plot
|
|
2
|
+
r"""
|
|
3
|
+
Interface for extracting data and generating images from Jmol readable files.
|
|
4
|
+
|
|
5
|
+
JmolData is a no GUI version of Jmol useful for extracting data from files Jmol
|
|
6
|
+
reads and for generating image files.
|
|
7
|
+
|
|
8
|
+
AUTHORS:
|
|
9
|
+
|
|
10
|
+
- Jonathan Gutow (2012-06-14): complete doctest coverage
|
|
11
|
+
- Jonathan Gutow (2012-03-21): initial version
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
# ******************************************************************************
|
|
15
|
+
# Copyright (C) 2012 Jonathan Gutow (gutow@uwosh.edu)
|
|
16
|
+
#
|
|
17
|
+
# Distributed under the terms of the GNU General Public License (GPL)
|
|
18
|
+
# as published by the Free Software Foundation; either version 2 of
|
|
19
|
+
# the License, or (at your option) any later version.
|
|
20
|
+
# https://www.gnu.org/licenses/
|
|
21
|
+
# ******************************************************************************
|
|
22
|
+
|
|
23
|
+
from sage.structure.sage_object import SageObject
|
|
24
|
+
|
|
25
|
+
from sage.features.jmol import JmolDataJar
|
|
26
|
+
from sage.misc.temporary_file import tmp_filename
|
|
27
|
+
from sage.cpython.string import bytes_to_str
|
|
28
|
+
|
|
29
|
+
import os
|
|
30
|
+
import re
|
|
31
|
+
import subprocess
|
|
32
|
+
from pathlib import Path
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class JmolData(SageObject):
|
|
36
|
+
r"""
|
|
37
|
+
.. TODO::
|
|
38
|
+
|
|
39
|
+
Create an animated image file (GIF) if spin is on and put data
|
|
40
|
+
extracted from a file into a variable/string/structure to return
|
|
41
|
+
"""
|
|
42
|
+
def __init__(self):
|
|
43
|
+
"""
|
|
44
|
+
EXAMPLES:
|
|
45
|
+
|
|
46
|
+
Create a JmolData object::
|
|
47
|
+
|
|
48
|
+
sage: from sage.interfaces.jmoldata import JmolData
|
|
49
|
+
sage: JData = JmolData()
|
|
50
|
+
"""
|
|
51
|
+
pass
|
|
52
|
+
|
|
53
|
+
def is_jvm_available(self):
|
|
54
|
+
"""
|
|
55
|
+
Return ``True`` if the Java Virtual Machine is available and ``False`` if not.
|
|
56
|
+
|
|
57
|
+
EXAMPLES:
|
|
58
|
+
|
|
59
|
+
Check that it returns a boolean::
|
|
60
|
+
|
|
61
|
+
sage: from sage.interfaces.jmoldata import JmolData
|
|
62
|
+
sage: JData = JmolData()
|
|
63
|
+
sage: type(JData.is_jvm_available())
|
|
64
|
+
<... 'bool'>
|
|
65
|
+
"""
|
|
66
|
+
try:
|
|
67
|
+
version = bytes_to_str(subprocess.check_output(['java', '-version'], stderr=subprocess.STDOUT))
|
|
68
|
+
except (subprocess.CalledProcessError, OSError):
|
|
69
|
+
return False
|
|
70
|
+
|
|
71
|
+
java_version_number = int(re.sub(r'.*version "(0\.|1\.)?(\d*)[\s\S]*', r'\2', version, flags=re.S))
|
|
72
|
+
return java_version_number >= 7
|
|
73
|
+
|
|
74
|
+
def jmolpath(self):
|
|
75
|
+
"""
|
|
76
|
+
Return the path to the jar file.
|
|
77
|
+
|
|
78
|
+
EXAMPLES::
|
|
79
|
+
|
|
80
|
+
sage: from sage.interfaces.jmoldata import JmolData
|
|
81
|
+
sage: JData = JmolData()
|
|
82
|
+
sage: JData.jmolpath() # needs jmol
|
|
83
|
+
'.../JmolData.jar'
|
|
84
|
+
"""
|
|
85
|
+
jmolpath = JmolDataJar().absolute_filename()
|
|
86
|
+
|
|
87
|
+
return jmolpath
|
|
88
|
+
|
|
89
|
+
def is_jmol_available(self):
|
|
90
|
+
"""
|
|
91
|
+
Return ``True`` if jmol is available and ``False`` if not.
|
|
92
|
+
|
|
93
|
+
EXAMPLES:
|
|
94
|
+
|
|
95
|
+
Check that it returns a boolean::
|
|
96
|
+
|
|
97
|
+
sage: from sage.interfaces.jmoldata import JmolData
|
|
98
|
+
sage: JData = JmolData()
|
|
99
|
+
sage: type(JData.is_jmol_available())
|
|
100
|
+
<... 'bool'>
|
|
101
|
+
"""
|
|
102
|
+
if not JmolDataJar().is_present():
|
|
103
|
+
return False
|
|
104
|
+
|
|
105
|
+
if not self.is_jvm_available():
|
|
106
|
+
return False
|
|
107
|
+
|
|
108
|
+
return True
|
|
109
|
+
|
|
110
|
+
def export_image(self,
|
|
111
|
+
targetfile,
|
|
112
|
+
datafile, # name (path) of data file Jmol can read or script file telling it what to read or load
|
|
113
|
+
datafile_cmd='script', # "script" or "load"
|
|
114
|
+
image_type='PNG', # PNG, JPG, GIF
|
|
115
|
+
figsize=5,
|
|
116
|
+
**kwds):
|
|
117
|
+
r"""
|
|
118
|
+
This executes JmolData.jar to make an image file.
|
|
119
|
+
|
|
120
|
+
INPUT:
|
|
121
|
+
|
|
122
|
+
- ``targetfile`` -- the full path to the file where the image
|
|
123
|
+
should be written
|
|
124
|
+
|
|
125
|
+
- ``datafile`` -- full path to the data file Jmol can read or
|
|
126
|
+
text of a script telling Jmol what to read or load
|
|
127
|
+
|
|
128
|
+
- ``datafile_cmd`` -- (default: ``'script'``) ``'load'`` or ``'script'``
|
|
129
|
+
should be ``'load'`` for a data file
|
|
130
|
+
|
|
131
|
+
- ``image_type`` -- (default: ``"PNG"``) ``'PNG'`` ``'JPG'`` or ``'GIF'``
|
|
132
|
+
|
|
133
|
+
- ``figsize`` -- number (default: 5) equal to (pixels/side)/100
|
|
134
|
+
|
|
135
|
+
OUTPUT: image file, .png, .gif or .jpg (default: .png)
|
|
136
|
+
|
|
137
|
+
.. NOTE::
|
|
138
|
+
|
|
139
|
+
Examples will generate an error message if a functional Java Virtual Machine (JVM)
|
|
140
|
+
is not installed on the machine the Sage instance is running on.
|
|
141
|
+
|
|
142
|
+
.. warning::
|
|
143
|
+
|
|
144
|
+
Programmers using this module should check that the JVM is
|
|
145
|
+
available before making calls to avoid the user getting
|
|
146
|
+
error messages. Check for the JVM using the function
|
|
147
|
+
:meth:`is_jvm_available`, which returns ``True`` if a JVM is available.
|
|
148
|
+
|
|
149
|
+
EXAMPLES:
|
|
150
|
+
|
|
151
|
+
Use Jmol to load a pdb file containing some DNA from a web data
|
|
152
|
+
base and make an image of the DNA. If you execute this in the
|
|
153
|
+
notebook, the image will appear in the output cell::
|
|
154
|
+
|
|
155
|
+
sage: from sage.interfaces.jmoldata import JmolData
|
|
156
|
+
sage: JData = JmolData()
|
|
157
|
+
sage: script = "load =1lcd;display DNA;moveto 0.0 { -473 -713 -518 59.94} 100.0 0.0 0.0 {21.17 26.72 27.295} 27.544636 {0.0 0.0 0.0} -25.287832 64.8414 0.0;"
|
|
158
|
+
sage: testfile = tmp_filename(ext="DNA.png")
|
|
159
|
+
sage: JData.export_image(targetfile=testfile,datafile=script,image_type="PNG") # optional -- java internet
|
|
160
|
+
sage: print(os.path.exists(testfile)) # optional -- java internet
|
|
161
|
+
True
|
|
162
|
+
|
|
163
|
+
Use Jmol to save an image of a 3-D object created in Sage.
|
|
164
|
+
This method is used internally by plot3d to generate static images.
|
|
165
|
+
This example doesn't have correct scaling::
|
|
166
|
+
|
|
167
|
+
sage: from sage.interfaces.jmoldata import JmolData
|
|
168
|
+
sage: JData = JmolData()
|
|
169
|
+
sage: D = dodecahedron() # needs sage.plot
|
|
170
|
+
sage: from tempfile import NamedTemporaryFile
|
|
171
|
+
sage: archive = NamedTemporaryFile(suffix='.zip')
|
|
172
|
+
sage: D.export_jmol(archive.name) # needs sage.plot
|
|
173
|
+
sage: archive_native = archive.name
|
|
174
|
+
sage: script = f'set defaultdirectory "f{archive_native}"\n'
|
|
175
|
+
sage: script += 'script SCRIPT\n'
|
|
176
|
+
sage: with NamedTemporaryFile(suffix='.png') as testfile: # optional - java, needs sage.plot
|
|
177
|
+
....: JData.export_image(targetfile=testfile.name,
|
|
178
|
+
....: datafile=script,
|
|
179
|
+
....: image_type="PNG")
|
|
180
|
+
....: os.path.exists(testfile.name)
|
|
181
|
+
True
|
|
182
|
+
sage: archive.close()
|
|
183
|
+
"""
|
|
184
|
+
# Set up paths, file names and scripts
|
|
185
|
+
jmolpath = self.jmolpath()
|
|
186
|
+
target_native = targetfile
|
|
187
|
+
|
|
188
|
+
launchscript = ""
|
|
189
|
+
if (datafile_cmd != 'script'):
|
|
190
|
+
launchscript = "load "
|
|
191
|
+
launchscript = launchscript + datafile
|
|
192
|
+
|
|
193
|
+
imagescript = 'write {} {!r}\n'.format(image_type, target_native)
|
|
194
|
+
size_arg = "%sx%s" % (figsize * 100, figsize * 100)
|
|
195
|
+
# Scratch file for Jmol errors
|
|
196
|
+
scratchout = tmp_filename(ext='.txt')
|
|
197
|
+
with open(scratchout, 'w') as jout:
|
|
198
|
+
# Now call the java application and write the file.
|
|
199
|
+
env = dict(os.environ)
|
|
200
|
+
env['LC_ALL'] = 'C'
|
|
201
|
+
env['LANG'] = 'C'
|
|
202
|
+
subprocess.call(["java", "-Xmx512m", "-Djava.awt.headless=true",
|
|
203
|
+
"-jar", jmolpath, "-iox", "-g", size_arg,
|
|
204
|
+
"-J", launchscript, "-j", imagescript],
|
|
205
|
+
stdout=jout, stderr=jout, env=env)
|
|
206
|
+
if not os.path.isfile(targetfile):
|
|
207
|
+
raise RuntimeError(f"Jmol failed to create file {targetfile}: {Path(scratchout).read_text()}")
|
|
208
|
+
os.unlink(scratchout)
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# sage_setup: distribution = sagemath-plot
|
|
2
|
+
r"""
|
|
3
|
+
POV-Ray, The Persistence of Vision Ray Tracer
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from sage.misc.pager import pager
|
|
7
|
+
import os
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class POVRay:
|
|
11
|
+
"""
|
|
12
|
+
POV-Ray The Persistence of Vision Ray Tracer
|
|
13
|
+
|
|
14
|
+
INPUT:
|
|
15
|
+
|
|
16
|
+
- ``pov_file`` -- complete path to the .pov file you want to be rendered
|
|
17
|
+
- ``outfile`` -- the filename you want to save your result to
|
|
18
|
+
- ``**kwargs`` -- additionally keyword arguments you want to pass to POVRay
|
|
19
|
+
|
|
20
|
+
OUTPUT: image is written to the file you specified in outfile
|
|
21
|
+
|
|
22
|
+
EXAMPLES:
|
|
23
|
+
|
|
24
|
+
AUTHOR:
|
|
25
|
+
|
|
26
|
+
Sage interface written by Yi Qiang (yqiang _atNOSPAM_ gmail.com)
|
|
27
|
+
|
|
28
|
+
POVRay: http://www.povray.org
|
|
29
|
+
"""
|
|
30
|
+
def __repr__(self):
|
|
31
|
+
return 'POV-Ray The Persistence of Vision Ray Tracer'
|
|
32
|
+
|
|
33
|
+
def __call__(self, pov_file, outfile='sage.ppm', block=True, **kwargs):
|
|
34
|
+
if not os.path.isfile(pov_file):
|
|
35
|
+
return "%s not found" % (pov_file)
|
|
36
|
+
|
|
37
|
+
outfile = os.path.abspath(os.path.expanduser(outfile))
|
|
38
|
+
|
|
39
|
+
if not ('W' in kwargs and 'H' in kwargs):
|
|
40
|
+
return "You must specify a width and height."
|
|
41
|
+
|
|
42
|
+
cmd = "povray -D +FP +I%s +O%s " % (pov_file, outfile)
|
|
43
|
+
for k, v in kwargs.items():
|
|
44
|
+
cmd += "+%s%s " % (k, v)
|
|
45
|
+
|
|
46
|
+
if not block:
|
|
47
|
+
cmd += ' &'
|
|
48
|
+
os.system(cmd)
|
|
49
|
+
|
|
50
|
+
def usage(self):
|
|
51
|
+
with os.popen('povray') as f:
|
|
52
|
+
r = f.read()
|
|
53
|
+
pager()(r)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
povray = POVRay()
|
sage/plot/all.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# sage_setup: distribution = sagemath-plot
|
|
2
|
+
from sage.plot.graphics import Graphics
|
|
3
|
+
from sage.plot.plot import (plot, graphics_array, multi_graphics, list_plot,
|
|
4
|
+
parametric_plot, polar_plot, plot_loglog, plot_semilogx,
|
|
5
|
+
plot_semilogy, list_plot_loglog, list_plot_semilogx,
|
|
6
|
+
list_plot_semilogy)
|
|
7
|
+
from sage.plot.line import line, line2d
|
|
8
|
+
from sage.plot.arrow import arrow, arrow2d
|
|
9
|
+
from sage.plot.bar_chart import bar_chart
|
|
10
|
+
from sage.plot.histogram import histogram
|
|
11
|
+
from sage.plot.bezier_path import bezier_path
|
|
12
|
+
from sage.plot.scatter_plot import scatter_plot
|
|
13
|
+
from sage.plot.disk import disk
|
|
14
|
+
from sage.plot.point import point, points, point2d
|
|
15
|
+
from sage.plot.matrix_plot import matrix_plot
|
|
16
|
+
from sage.plot.plot_field import plot_vector_field, plot_slope_field
|
|
17
|
+
from sage.plot.text import text
|
|
18
|
+
from sage.plot.polygon import polygon, polygon2d
|
|
19
|
+
from sage.plot.circle import circle
|
|
20
|
+
from sage.plot.ellipse import ellipse
|
|
21
|
+
from sage.plot.contour_plot import contour_plot, implicit_plot, region_plot
|
|
22
|
+
from sage.plot.density_plot import density_plot
|
|
23
|
+
from sage.plot.streamline_plot import streamline_plot
|
|
24
|
+
|
|
25
|
+
from sage.misc.lazy_import import lazy_import
|
|
26
|
+
lazy_import("sage.plot.complex_plot", ["complex_plot"])
|
|
27
|
+
|
|
28
|
+
from sage.plot.arc import arc
|
|
29
|
+
|
|
30
|
+
from sage.plot.animate import animate
|
|
31
|
+
|
|
32
|
+
lazy_import('sage.plot.plot3d.tachyon', 'Tachyon')
|
|
33
|
+
|
|
34
|
+
from sage.plot.colors import Color, hue, rainbow, colors, colormaps
|
|
35
|
+
|
|
36
|
+
from sage.plot.step import plot_step_function
|
|
37
|
+
|
|
38
|
+
lazy_import("sage.plot.hyperbolic_arc", "hyperbolic_arc")
|
|
39
|
+
lazy_import("sage.plot.hyperbolic_polygon", [
|
|
40
|
+
"hyperbolic_triangle", "hyperbolic_polygon"])
|
|
41
|
+
lazy_import("sage.plot.hyperbolic_regular_polygon", "hyperbolic_regular_polygon")
|
|
42
|
+
del lazy_import
|