sympy

how to handle an asymptote/discontinuity with Matplotlib

微笑、不失礼 提交于 2019-11-26 12:43:38
问题 When plotting a graph with a discontinuity/asymptote/singularity/whatever, is there any automatic way to prevent Matplotlib from \'joining the dots\' across the \'break\'? (please see code/image below). I read that Sage has a [detect_poles] facility that looked good, but I really want it to work with Matplotlib. import matplotlib.pyplot as plt import numpy as np from sympy import sympify, lambdify from sympy.abc import x fig = plt.figure(1) ax = fig.add_subplot(111) # set up axis ax.spines[\

How to solve a pair of nonlinear equations using Python?

余生长醉 提交于 2019-11-26 03:38:33
问题 What\'s the (best) way to solve a pair of non linear equations using Python. (Numpy, Scipy or Sympy) eg: x+y^2 = 4 e^x+ xy = 3 A code snippet which solves the above pair will be great 回答1: for numerical solution, you can use fsolve: http://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.fsolve.html#scipy.optimize.fsolve from scipy.optimize import fsolve import math def equations(p): x, y = p return (x+y**2-4, math.exp(x) + x*y - 3) x, y = fsolve(equations, (1, 1)) print equations(

Is it possible to plot implicit equations using Matplotlib?

♀尐吖头ヾ 提交于 2019-11-26 02:08:27
I would like to plot implicit equations (of the form f(x, y)=g(x, y) eg. X^y=y^x) in Matplotlib. Is this possible? Steve I don't believe there's very good support for this, but you could try something like import matplotlib.pyplot from numpy import arange from numpy import meshgrid delta = 0.025 xrange = arange(-5.0, 20.0, delta) yrange = arange(-5.0, 20.0, delta) X, Y = meshgrid(xrange,yrange) # F is one side of the equation, G is the other F = Y**X G = X**Y matplotlib.pyplot.contour(X, Y, (F - G), [0]) matplotlib.pyplot.show() See the API docs for contour : if the fourth argument is a

Is it possible to plot implicit equations using Matplotlib?

我们两清 提交于 2019-11-26 01:08:43
问题 I would like to plot implicit equations (of the form f(x, y)=g(x, y) eg. X^y=y^x) in Matplotlib. Is this possible? 回答1: I don't believe there's very good support for this, but you could try something like import matplotlib.pyplot from numpy import arange from numpy import meshgrid delta = 0.025 xrange = arange(-5.0, 20.0, delta) yrange = arange(-5.0, 20.0, delta) X, Y = meshgrid(xrange,yrange) # F is one side of the equation, G is the other F = Y**X G = X**Y matplotlib.pyplot.contour(X, Y, (F