您的位置:首页 > 编程语言 > Python开发

python Matplotlib 画心形线(极坐标 直角坐标参数方程)

2017-09-03 14:15 1371 查看
1.极坐标

# -*- coding:utf8 -*-
# __author__ = 'wangxuhao'
# __file__ = 'Cardioid_polar'

import numpy as np
import matplotlib.pyplot as plt

theta = np.linspace(0, 2*np.pi, 1000)
y = np.pi * (1 - np.sin(theta))
graph = plt.subplot(111, polar=True)
graph.plot(theta, y,color='red', linewidth=2)
plt.show()



这个有一点胖了。。。

2.直角坐标的参数方程

# -*- coding:utf8 -*-
# __author__ = 'wangxuhao'
# __file__ = 'Cardioid'

import matplotlib.pyplot as plt
import numpy as np
import math

t = np.linspace(0, math.pi, 1000)
x = np.sin(t)
y = np.cos(t) + np.power(x, 2.0 / 3)
plt.plot(x, y, color='red', linewidth=2)
plt.plot(-x, y, color='red', linewidth=2)
plt.title("heart")
plt.ylim(-2, 2)
plt.xlim(-2, 2)
plt.show()

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: