本文整理汇总了Python中sage.plot.graphics.Graphics.set_aspect_ratio方法的典型用法代码示例。如果您正苦于以下问题:Python Graphics.set_aspect_ratio方法的具体用法?Python Graphics.set_aspect_ratio怎么用?Python Graphics.set_aspect_ratio使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sage.plot.graphics.Graphics
的用法示例。
在下文中一共展示了Graphics.set_aspect_ratio方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: plot_fan_stereographically
# 需要导入模块: from sage.plot.graphics import Graphics [as 别名]
# 或者: from sage.plot.graphics.Graphics import set_aspect_ratio [as 别名]
def plot_fan_stereographically(rays, walls, northsign=1, north=vector((-1,-1,-1)), right=vector((1,0,0)), colors=None, thickness=None):
from sage.plot.graphics import Graphics
from sage.plot.point import point
from sage.misc.flatten import flatten
from sage.plot.line import line
from sage.misc.functional import norm
if colors == None:
colors = dict([('walls','black'),('rays','red')])
if thickness == None:
thickness = dict([('walls',0.5),('rays',20)])
G = Graphics()
for (u,v) in walls:
G += _stereo_arc(vector(u),vector(v),vector(u+v),north=northsign*north,right=right,color=colors['walls'],thickness=thickness['walls'],zorder=len(G))
for v in rays:
G += point(_stereo_coordinates(vector(v),north=northsign*north,right=right),color=colors['rays'],zorder=len(G),size=thickness['rays'])
G.set_aspect_ratio(1)
G._show_axes = False
return G
示例2: plot_cluster_fan_stereographically
# 需要导入模块: from sage.plot.graphics import Graphics [as 别名]
# 或者: from sage.plot.graphics.Graphics import set_aspect_ratio [as 别名]
def plot_cluster_fan_stereographically(self, northsign=1, north=None, right=None, colors=None):
from sage.plot.graphics import Graphics
from sage.plot.point import point
from sage.misc.flatten import flatten
from sage.plot.line import line
from sage.misc.functional import norm
if self.rk !=3:
raise ValueError("Can only stereographically project fans in 3d.")
if not self.is_finite() and self._depth == infinity:
raise ValueError("For infinite algebras you must specify the depth.")
if north == None:
if self.is_affine():
north = vector(self.delta())
else:
north = vector( (-1,-1,-1) )
if right == None:
if self.is_affine():
right = vector(self.gamma())
else:
right = vector( (1,0,0) )
if colors == None:
colors = dict([(0,'red'),(1,'green'),(2,'blue'),(3,'cyan'),(4,'yellow')])
G = Graphics()
roots = list(self.g_vectors())
compatible = []
while roots:
x = roots.pop()
for y in roots:
if self.compatibility_degree(x,y) == 0:
compatible.append((x,y))
for (u,v) in compatible:
G += _stereo_arc(vector(u),vector(v),vector(u+v),north=northsign*north,right=right,thickness=0.5,color='black')
for i in range(3):
orbit = self.ith_orbit(i)
for j in orbit:
G += point(_stereo_coordinates(vector(orbit[j]),north=northsign*north,right=right),color=colors[i],zorder=len(G))
if self.is_affine():
tube_vectors = map(vector,flatten(self.affine_tubes()))
for v in tube_vectors:
G += point(_stereo_coordinates(v,north=northsign*north,right=right),color=colors[3],zorder=len(G))
if north != vector(self.delta()):
G += _stereo_arc(tube_vectors[0],tube_vectors[1],vector(self.delta()),north=northsign*north,right=right,thickness=2,color=colors[4],zorder=0)
else:
# FIXME: refactor this before publishing
tube_projections = [
_stereo_coordinates(v,north=northsign*north,right=right)
for v in tube_vectors ]
t=min((G.get_minmax_data()['xmax'],G.get_minmax_data()['ymax']))
G += line([tube_projections[0],tube_projections[0]+t*(_normalize(tube_projections[0]-tube_projections[1]))],thickness=2,color=colors[4],zorder=0)
G += line([tube_projections[1],tube_projections[1]+t*(_normalize(tube_projections[1]-tube_projections[0]))],thickness=2,color=colors[4],zorder=0)
G.set_aspect_ratio(1)
G._show_axes = False
return G
示例3: plot2d
# 需要导入模块: from sage.plot.graphics import Graphics [as 别名]
# 或者: from sage.plot.graphics.Graphics import set_aspect_ratio [as 别名]
def plot2d(self,depth=None):
# FIXME: refactor this before publishing
from sage.plot.line import line
from sage.plot.graphics import Graphics
if self._n !=2:
raise ValueError("Can only 2d plot fans.")
if depth == None:
depth = self._depth
if not self.is_finite() and depth==infinity:
raise ValueError("For infinite algebras you must specify the depth.")
colors = dict([(0,'red'),(1,'green')])
G = Graphics()
for i in range(2):
orbit = self.ith_orbit(i,depth=depth)
for j in orbit:
G += line([(0,0),vector(orbit[j])],color=colors[i],thickness=0.5, zorder=2*j+1)
G.set_aspect_ratio(1)
G._show_axes = False
return G
示例4: plot
# 需要导入模块: from sage.plot.graphics import Graphics [as 别名]
# 或者: from sage.plot.graphics.Graphics import set_aspect_ratio [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
示例5: finalize
# 需要导入模块: from sage.plot.graphics import Graphics [as 别名]
# 或者: from sage.plot.graphics.Graphics import set_aspect_ratio [as 别名]
def finalize(self, G):
r"""
Finalize a root system plot.
INPUT:
- ``G`` -- a root system plot or ``0``
This sets the aspect ratio to 1 and remove the axes. This
should be called by all the user-level plotting methods of
root systems. This will become mostly obsolete when
customization options won't be lost anymore upon addition of
graphics objects and there will be a proper empty object for
2D and 3D plots.
EXAMPLES::
sage: L = RootSystem(["B",2,1]).ambient_space()
sage: options = L.plot_parse_options()
sage: p = L.plot_roots(plot_options=options)
sage: p += L.plot_coroots(plot_options=options)
sage: p.axes()
True
sage: p = options.finalize(p)
sage: p.axes()
False
sage: p.aspect_ratio()
1.0
sage: options = L.plot_parse_options(affine=False)
sage: p = L.plot_roots(plot_options=options)
sage: p += point([[1,1,0]])
sage: p = options.finalize(p)
sage: p.aspect_ratio()
[1.0, 1.0, 1.0]
If the input is ``0``, this returns an empty graphics object::
sage: type(options.finalize(0))
<class 'sage.plot.plot3d.base.Graphics3dGroup'>
sage: options = L.plot_parse_options()
sage: type(options.finalize(0))
<class 'sage.plot.graphics.Graphics'>
sage: list(options.finalize(0))
[]
"""
from sage.plot.graphics import Graphics
if self.dimension == 2:
if G == 0:
G = Graphics()
G.set_aspect_ratio(1)
# TODO: make this customizable
G.axes(False)
elif self.dimension == 3:
if G == 0:
from sage.plot.plot3d.base import Graphics3dGroup
G = Graphics3dGroup()
G.aspect_ratio(1)
# TODO: Configuration axes
return G
示例6: plot
# 需要导入模块: from sage.plot.graphics import Graphics [as 别名]
# 或者: from sage.plot.graphics.Graphics import set_aspect_ratio [as 别名]
#.........这里部分代码省略.........
# TODO: THIS SHOULD USE THE EXISTING PLOT OF ARCS!
# plot the arc from p to q differently depending on the type of self
p = ZZ(p)
q = ZZ(q)
t = var('t')
if p - q in [1, -1]:
def f(t):
return (radius * cos(t), radius * sin(t))
(p, q) = sorted([p, q])
angle_p = vertex_to_angle(p)
angle_q = vertex_to_angle(q)
return parametric_plot(f(t), (t, angle_q, angle_p), **opts)
if self.type() == 'A':
angle_p = vertex_to_angle(p)
angle_q = vertex_to_angle(q)
if angle_p < angle_q:
angle_p += 2 * pi
internal_angle = angle_p - angle_q
if internal_angle > pi:
(angle_p, angle_q) = (angle_q + 2 * pi, angle_p)
internal_angle = angle_p - angle_q
angle_center = (angle_p+angle_q) / 2
hypotenuse = radius / cos(internal_angle / 2)
radius_arc = hypotenuse * sin(internal_angle / 2)
center = (hypotenuse * cos(angle_center),
hypotenuse * sin(angle_center))
center_angle_p = angle_p + pi / 2
center_angle_q = angle_q + 3 * pi / 2
def f(t):
return (radius_arc * cos(t) + center[0],
radius_arc * sin(t) + center[1])
return parametric_plot(f(t), (t, center_angle_p,
center_angle_q), **opts)
elif self.type() == 'D':
if p >= q:
q += self.r()
px = -2 * pi * p / self.r() + pi / 2
qx = -2 * pi * q / self.r() + pi / 2
arc_radius = (px - qx) / 2
arc_center = qx + arc_radius
def f(t):
return exp(I * ((cos(t) + I * sin(t)) *
arc_radius + arc_center)) * radius
return parametric_plot((real_part(f(t)), imag_part(f(t))),
(t, 0, pi), **opts)
def vertex_to_angle(v):
# v==0 corresponds to pi/2
return -2 * pi * RR(v) / self.r() + 5 * pi / 2
# Begin plotting
P = Graphics()
# Shade neuter intervals
neuter_intervals = [x for x in flatten(self.intervals()[:-1],
max_level=1)
if x[2] in ["NR", "NL"]]
shaded_triangles = map(triangle, neuter_intervals)
for (p, q, r) in shaded_triangles:
points = list(plot_arc(radius, p, q)[0])
points += list(plot_arc(radius, q, r)[0])
points += list(reversed(plot_arc(radius, p, r)[0]))
P += polygon2d(points, **shading_opts)
# Disk boundary
P += circle((0, 0), radius, **triangulation_opts)
# Triangulation
for (p, q) in self.triangulation():
P += plot_arc(radius, p, q, **triangulation_opts)
if self.type() == 'D':
s = radius / 50.0
P += polygon2d([(s, 5 * s), (s, 7 * s),
(3 * s, 5 * s), (3 * s, 7 * s)],
color=triangulation_opts['color'])
P += bezier_path([[(0, 0), (2 * s, 1 * s), (2 * s, 6 * s)],
[(2 * s, 10 * s), (s, 20 * s)],
[(0, 30 * s), (0, radius)]],
**triangulation_opts)
P += bezier_path([[(0, 0), (-2 * s, 1 * s), (-2 * s, 6 * s)],
[(-2 * s, 10 * s), (-s, 20 * s)],
[(0, 30 * s), (0, radius)]],
**triangulation_opts)
P += point((0, 0), zorder=len(P), **points_opts)
# Vertices
v_points = {x: (radius * cos(vertex_to_angle(x)),
radius * sin(vertex_to_angle(x)))
for x in self.vertices()}
for v in v_points:
P += point(v_points[v], zorder=len(P), **points_opts)
# Reflection axes
P += line([(0, 1.1 * radius), (0, -1.1 * radius)],
zorder=len(P), **reflections_opts)
axis_angle = vertex_to_angle(-0.5 * (self.rk() + (1, 1))[1])
(a, b) = (1.1 * radius * cos(axis_angle),
1.1 * radius * sin(axis_angle))
P += line([(a, b), (-a, -b)], zorder=len(P), **reflections_opts)
# Wrap up
P.set_aspect_ratio(1)
P.axes(False)
return P
示例7: _graphics
# 需要导入模块: from sage.plot.graphics import Graphics [as 别名]
# 或者: from sage.plot.graphics.Graphics import set_aspect_ratio [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