本文整理汇总了Python中sympy.Plot.show方法的典型用法代码示例。如果您正苦于以下问题:Python Plot.show方法的具体用法?Python Plot.show怎么用?Python Plot.show使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sympy.Plot
的用法示例。
在下文中一共展示了Plot.show方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from sympy import Plot [as 别名]
# 或者: from sympy.Plot import show [as 别名]
def main():
print(__doc__)
x = symbols('x')
# a numpy array we can apply the ufuncs to
grid = np.linspace(-1, 1, 1000)
# set mpmath precision to 20 significant numbers for verification
mpmath.mp.dps = 20
print("Compiling legendre ufuncs and checking results:")
# Let's also plot the ufunc's we generate
plot1 = Plot(visible=False)
for n in range(6):
# Setup the SymPy expression to ufuncify
expr = legendre(n, x)
print("The polynomial of degree %i is" % n)
pprint(expr)
# This is where the magic happens:
binary_poly = ufuncify(x, expr)
# It's now ready for use with numpy arrays
polyvector = binary_poly(grid)
# let's check the values against mpmath's legendre function
maxdiff = 0
for j in range(len(grid)):
precise_val = mpmath.legendre(n, grid[j])
diff = abs(polyvector[j] - precise_val)
if diff > maxdiff:
maxdiff = diff
print("The largest error in applied ufunc was %e" % maxdiff)
assert maxdiff < 1e-14
# We can also attach the autowrapped legendre polynomial to a sympy
# function and plot values as they are calculated by the binary function
g = implemented_function('g', binary_poly)
plot1[n] = g(x), [200]
print("Here's a plot with values calculated by the wrapped binary functions")
plot1.show()
示例2: plot_beam
# 需要导入模块: from sympy import Plot [as 别名]
# 或者: from sympy.Plot import show [as 别名]
def plot_beam(beam, **kwargs):
"""Plot the beam radius as it propagates in space.
Uses pyglet and ctype libraries
Parameters
==========
beam : BeamParameter for gaussian beam
z_range : plot range for the beam propagation coordinate
See Also
========
BeamParameter
plot_beam2
Examples
========
>>> from sympy.physics.gaussopt import BeamParameter, plot_beam
>>> b = BeamParameter(530e-9, 1, w=1e-5)
>>> plot_beam(b,z_range=2*b.z_r)
"""
if len(kwargs) != 1:
raise ValueError("The function expects only one named argument")
elif 'z_range' in kwargs :
z_range = sympify(kwargs['z_range'])
else :
raise ValueError(filldedent('''
The functions expects the z_range as a named argument'''))
x = symbols('x')
# TODO beam.w_0 *
# pyglet needs to have better zoom adjustment for geting a normal view
weist_d = sqrt(1+(x/beam.z_r)**2)
p = Plot(visible=False)
p[1] = weist_d, 'color=black', [x, -z_range, z_range, int(beam.w_0**-1)]
p[2] = -weist_d, 'color=black', [x, -z_range, z_range, int(beam.w_0**-1)]
p.adjust_all_bounds()
p.show()