本文整理汇总了Python中sage.plot.graphics.Graphics._extra_kwds['axes_labels']方法的典型用法代码示例。如果您正苦于以下问题:Python Graphics._extra_kwds['axes_labels']方法的具体用法?Python Graphics._extra_kwds['axes_labels']怎么用?Python Graphics._extra_kwds['axes_labels']使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sage.plot.graphics.Graphics
的用法示例。
在下文中一共展示了Graphics._extra_kwds['axes_labels']方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: plot
# 需要导入模块: from sage.plot.graphics import Graphics [as 别名]
# 或者: from sage.plot.graphics.Graphics import _extra_kwds['axes_labels'] [as 别名]
#.........这里部分代码省略.........
eff_curve = mapping.restrict(self.codomain()) * self
#
# The chart w.r.t. which the curve is plotted
#
if chart is None:
chart = eff_curve._codomain.default_chart()
elif not isinstance(chart, Chart):
raise TypeError("{} is not a chart".format(chart))
#
# Coordinates of the above chart w.r.t. which the curve is plotted
#
if ambient_coords is None:
ambient_coords = chart[:] # all chart coordinates are used
n_pc = len(ambient_coords)
if n_pc != 2 and n_pc !=3:
raise ValueError("The number of coordinates involved in the " +
"plot must be either 2 or 3, not {}".format(n_pc))
ind_pc = [chart[:].index(pc) for pc in ambient_coords] # indices of plot
# coordinates
#
# Parameter range for the plot
#
if prange is None:
prange = (self._domain.lower_bound(), self._domain.upper_bound())
elif not isinstance(prange, (tuple, list)):
raise TypeError("{} is neither a tuple nor a list".format(prange))
elif len(prange) != 2:
raise ValueError("the argument prange must be a tuple/list " +
"of 2 elements")
tmin = prange[0]
tmax = prange[1]
if tmin == -Infinity:
tmin = -max_value
elif not include_end_point[0]:
tmin = tmin + end_point_offset[0]
if tmax == Infinity:
tmax = max_value
elif not include_end_point[1]:
tmax = tmax - end_point_offset[1]
tmin = numerical_approx(tmin)
tmax = numerical_approx(tmax)
#
# The coordinate expression of the effective curve
#
canon_chart = self._domain.canonical_chart()
transf = None
for chart_pair in eff_curve._coord_expression:
if chart_pair == (canon_chart, chart):
transf = eff_curve._coord_expression[chart_pair]
break
else:
# Search for a subchart
for chart_pair in eff_curve._coord_expression:
for schart in chart._subcharts:
if chart_pair == (canon_chart, schart):
transf = eff_curve._coord_expression[chart_pair]
if transf is None:
raise ValueError("No expression has been found for " +
"{} in terms of {}".format(self, format))
#
# List of points for the plot curve
#
plot_curve = []
dt = (tmax - tmin) / (plot_points - 1)
t = tmin
if parameters is None:
for i in range(plot_points):
x = transf(t, simplify=False)
plot_curve.append( [numerical_approx(x[j]) for j in ind_pc] )
t += dt
else:
for i in range(plot_points):
x = transf(t, simplify=False)
plot_curve.append(
[numerical_approx( x[j].substitute(parameters) )
for j in ind_pc] )
t += dt
#
# The plot
#
resu = Graphics()
resu += line(plot_curve, color=color, linestyle=style,
thickness=thickness)
if n_pc==2: # 2D graphic
resu.set_aspect_ratio(aspect_ratio)
if label_axes:
# We update the dictionary _extra_kwds (options to be passed
# to show()), instead of using the method
# Graphics.axes_labels() since the latter is not robust w.r.t.
# graph addition
resu._extra_kwds['axes_labels'] = [r'$'+latex(pc)+r'$'
for pc in ambient_coords]
else: # 3D graphic
if aspect_ratio == 'automatic':
aspect_ratio = 1
resu.aspect_ratio(aspect_ratio)
if label_axes:
labels = [str(pc) for pc in ambient_coords]
resu = set_axes_labels(resu, *labels)
return resu
示例2: plot
# 需要导入模块: from sage.plot.graphics import Graphics [as 别名]
# 或者: from sage.plot.graphics.Graphics import _extra_kwds['axes_labels'] [as 别名]
#.........这里部分代码省略.........
xx[ind_coord[i]] = xmin[i] + ind[i]*step_tab[i]
if chart_domain.valid_coordinates(*xx, tolerance=1e-13,
parameters=parameters):
# needed a xx*1 to copy the list by value
list_xx.append(xx*1)
# Next index:
ret = 1
for pos in range(ncp-1,-1,-1):
imax = number_values[coords[pos]] - 1
if ind[pos] != imax:
ind[pos] += ret
ret = 0
elif ret == 1:
if pos == 0:
ind[pos] = imax + 1 # end point reached
else:
ind[pos] = 0
ret = 1
lol = lambda lst, sz: [lst[i:i+sz] for i in range(0, len(lst), sz)]
ind_step = max(1, int(len(list_xx)/nproc/2))
local_list = lol(list_xx,ind_step)
# definition of the list of input parameters
listParalInput = [(vector, dom, ind_part,
chart_domain, chart,
ambient_coords, mapping,
scale, color, parameters,
extra_options)
for ind_part in local_list]
# definition of the parallel function
@parallel(p_iter='multiprocessing', ncpus=nproc)
def add_point_plot(vector, dom, xx_list, chart_domain, chart,
ambient_coords, mapping, scale, color,
parameters, extra_options):
count = 0
for xx in xx_list:
point = dom(xx, chart=chart_domain)
part = vector.at(point).plot(chart=chart,
ambient_coords=ambient_coords,
mapping=mapping,scale=scale,
color=color, print_label=False,
parameters=parameters,
**extra_options)
if count == 0:
local_resu = part
else:
local_resu += part
count += 1
return local_resu
# parallel execution and reconstruction of the plot
for ii, val in add_point_plot(listParalInput):
resu += val
else:
# sequential plot
while ind != ind_max:
for i in range(ncp):
xx[ind_coord[i]] = xmin[i] + ind[i]*step_tab[i]
if chart_domain.valid_coordinates(*xx, tolerance=1e-13,
parameters=parameters):
point = dom(xx, chart=chart_domain)
resu += vector.at(point).plot(chart=chart,
ambient_coords=ambient_coords,
mapping=mapping, scale=scale,
color=color, print_label=False,
parameters=parameters,
**extra_options)
# Next index:
ret = 1
for pos in range(ncp-1, -1, -1):
imax = number_values[coords[pos]] - 1
if ind[pos] != imax:
ind[pos] += ret
ret = 0
elif ret == 1:
if pos == 0:
ind[pos] = imax + 1 # end point reached
else:
ind[pos] = 0
ret = 1
if label_axes:
if nca == 2: # 2D graphic
# We update the dictionary _extra_kwds (options to be passed
# to show()), instead of using the method
# Graphics.axes_labels() since the latter is not robust w.r.t.
# graph addition
resu._extra_kwds['axes_labels'] = [r'$'+latex(ac)+r'$'
for ac in ambient_coords]
else: # 3D graphic
labels = [str(ac) for ac in ambient_coords]
resu = set_axes_labels(resu, *labels)
return resu
示例3: plot
# 需要导入模块: from sage.plot.graphics import Graphics [as 别名]
# 或者: from sage.plot.graphics.Graphics import _extra_kwds['axes_labels'] [as 别名]
#.........这里部分代码省略.........
if nca != 2 and nca !=3:
raise ValueError("the number of ambient coordinates must be " +
"either 2 or 3, not {}".format(nca))
if ranges is None:
ranges = {}
ranges0 = {}
for coord in coords:
if coord in ranges:
ranges0[coord] = (numerical_approx(ranges[coord][0]),
numerical_approx(ranges[coord][1]))
else:
bounds = chart_domain._bounds[chart_domain[:].index(coord)]
if bounds[0][0] == -Infinity:
xmin = numerical_approx(-max_value)
elif bounds[0][1]:
xmin = numerical_approx(bounds[0][0])
else:
xmin = numerical_approx(bounds[0][0] + 1.e-3)
if bounds[1][0] == Infinity:
xmax = numerical_approx(max_value)
elif bounds[1][1]:
xmax = numerical_approx(bounds[1][0])
else:
xmax = numerical_approx(bounds[1][0] - 1.e-3)
ranges0[coord] = (xmin, xmax)
ranges = ranges0
if nb_values is None:
if nca == 2: # 2D plot
nb_values = 9
else: # 3D plot
nb_values = 5
if not isinstance(nb_values, dict):
nb_values0 = {}
for coord in coords:
nb_values0[coord] = nb_values
nb_values = nb_values0
if steps is None:
steps = {}
for coord in coords:
if coord not in steps:
steps[coord] = (ranges[coord][1] - ranges[coord][0])/ \
(nb_values[coord]-1)
else:
nb_values[coord] = 1 + int(
(ranges[coord][1] - ranges[coord][0])/ steps[coord])
#
# 2/ Plots
# -----
dom = chart_domain.domain()
nc = len(chart_domain[:])
ncp = len(coords)
xx = [0] * nc
if fixed_coords is not None:
if len(fixed_coords) != nc - ncp:
raise ValueError("Bad number of fixed coordinates.")
for fc, val in fixed_coords.iteritems():
xx[chart_domain[:].index(fc)] = val
index_p = [chart_domain[:].index(cd) for cd in coords]
resu = Graphics()
ind = [0] * ncp
ind_max = [0] * ncp
ind_max[0] = nb_values[coords[0]]
xmin = [ranges[cd][0] for cd in coords]
step_tab = [steps[cd] for cd in coords]
while ind != ind_max:
for i in range(ncp):
xx[index_p[i]] = xmin[i] + ind[i]*step_tab[i]
if chart_domain.valid_coordinates(*xx, tolerance=1e-13,
parameters=parameters):
point = dom(xx, chart=chart_domain)
resu += self.at(point).plot(chart=chart,
ambient_coords=ambient_coords, mapping=mapping,
scale=scale, color=color, print_label=False,
parameters=parameters,
**extra_options)
# Next index:
ret = 1
for pos in range(ncp-1,-1,-1):
imax = nb_values[coords[pos]] - 1
if ind[pos] != imax:
ind[pos] += ret
ret = 0
elif ret == 1:
if pos == 0:
ind[pos] = imax + 1 # end point reached
else:
ind[pos] = 0
ret = 1
if label_axes:
if nca==2: # 2D graphic
# We update the dictionary _extra_kwds (options to be passed
# to show()), instead of using the method
# Graphics.axes_labels() since the latter is not robust w.r.t.
# graph addition
resu._extra_kwds['axes_labels'] = [r'$'+latex(ac)+r'$'
for ac in ambient_coords]
else: # 3D graphic
labels = [str(ac) for ac in ambient_coords]
resu = set_axes_labels(resu, *labels)
return resu
示例4: _graphics
# 需要导入模块: from sage.plot.graphics import Graphics [as 别名]
# 或者: from sage.plot.graphics.Graphics import _extra_kwds['axes_labels'] [as 别名]
def _graphics(self, plot_curve, ambient_coords, thickness=1,
aspect_ratio='automatic', color='red', style='-',
label_axes=True):
r"""
Plot a 2D or 3D curve in a Cartesian graph with axes labeled by
the ambient coordinates; it is invoked by the methods
:meth:`plot` of
:class:`~sage.manifolds.differentiable.curve.DifferentiableCurve`,
and its subclasses
(:class:`~sage.manifolds.differentiable.integrated_curve.IntegratedCurve`,
:class:`~sage.manifolds.differentiable.integrated_curve.IntegratedAutoparallelCurve`,
and
:class:`~sage.manifolds.differentiable.integrated_curve.IntegratedGeodesic`).
TESTS::
sage: M = Manifold(2, 'R^2')
sage: X.<x,y> = M.chart()
sage: R.<t> = RealLine()
sage: c = M.curve([cos(t), sin(t)], (t, 0, 2*pi), name='c')
sage: graph = c._graphics([[1,2], [3,4]], [x,y])
sage: graph._objects[0].xdata == [1,3]
True
sage: graph._objects[0].ydata == [2,4]
True
sage: graph._objects[0]._options['thickness'] == 1
True
sage: graph._extra_kwds['aspect_ratio'] == 'automatic'
True
sage: graph._objects[0]._options['rgbcolor'] == 'red'
True
sage: graph._objects[0]._options['linestyle'] == '-'
True
sage: l = [r'$'+latex(x)+r'$', r'$'+latex(y)+r'$']
sage: graph._extra_kwds['axes_labels'] == l
True
"""
from sage.plot.graphics import Graphics
from sage.plot.line import line
from sage.manifolds.utilities import set_axes_labels
#
# The plot
#
n_pc = len(ambient_coords)
resu = Graphics()
resu += line(plot_curve, color=color, linestyle=style,
thickness=thickness)
if n_pc == 2: # 2D graphic
resu.set_aspect_ratio(aspect_ratio)
if label_axes:
# We update the dictionary _extra_kwds (options to be passed
# to show()), instead of using the method
# Graphics.axes_labels() since the latter is not robust w.r.t.
# graph addition
resu._extra_kwds['axes_labels'] = [r'$'+latex(pc)+r'$'
for pc in ambient_coords]
else: # 3D graphic
if aspect_ratio == 'automatic':
aspect_ratio = 1
resu.aspect_ratio(aspect_ratio)
if label_axes:
labels = [str(pc) for pc in ambient_coords]
resu = set_axes_labels(resu, *labels)
return resu