600字范文,内容丰富有趣,生活中的好帮手!
600字范文 > python动态心形代码-Python数学方程式画心型图案源码示例

python动态心形代码-Python数学方程式画心型图案源码示例

时间:2024-01-18 06:46:12

相关推荐

python动态心形代码-Python数学方程式画心型图案源码示例

如下几个心型图案,是用Python科学计算,根据数学方程式画出的。虽然心型不是特别的完美,但大体效果还是呈现出来了,还可以做更多的改进。

"""

'17*x^2 - 16*|x|*y + 17*y^2 = 225'

"""

import numpy as np

import matplotlib.pyplot as plt

X = np.arange(-5.0, 5.0, 0.1)

Y = np.arange(-5.0, 5.0, 0.1)

#

x, y = np.meshgrid(X, Y)

f = 17 * x ** 2 - 16 * np.abs(x) * y + 17 * y ** 2 - 225

fig = plt.figure()

cs = plt.contour(x, y, f, 0, colors = 'r')

plt.show()

"""

'(x^2+y^2+y)^2 = x^2 + y^2'

"""

import numpy as np

import matplotlib.pyplot as plt

X = np.arange(-2.0, 2.0, 0.05)

Y = np.arange(-2.0, 2.0, 0.05)

x, y = np.meshgrid(X, Y)

f = (x ** 2 + y ** 2 + y) ** 2 - x ** 2 - y ** 2

fig = plt.figure()

cs = plt.contour(x, y, f, 0, colors = 'r')

plt.show()

"""

'8*x^2 - 9*|x|*y + 8*y^2 = 17'

"""

import numpy as np

import matplotlib.pyplot as plt

X = np.arange(-2.5, 2.5, 0.05)

Y = np.arange(-2.5, 2.5, 0.05)

x, y = np.meshgrid(X, Y)

f = 8 * x ** 2 - 9 * np.abs(x) * y + 8 * y ** 2 - 17

fig = plt.figure()

cs = plt.contour(x, y, f, 0, colors = 'r')

plt.show()

"""

'(x^2 + y^2 - 1)^3 - x^2*y^3 = 0'

"""

import numpy as np

import matplotlib.pyplot as plt

import math

X = np.arange(-2.0, 2.0, 0.05)

Y = np.arange(-2.0, 2.0, 0.05)

x, y = np.meshgrid(X, Y)

f = (x ** 2 + y ** 2 - 1) ** 2 * (x ** 2 + y ** 2 - 1)- x ** 2 * y ** 2 * y

fig = plt.figure()

cs = plt.contour(x, y, f, 0, colors = 'r')

plt.show()

玩蛇网文章,转载请注明出处和文章网址:/code/graphics/gr2179.html

相关文章 Recommend

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。