+ -
当前位置:首页 → 问答吧 → matpoltlib绘制爱的方程式

matpoltlib绘制爱的方程式

时间:2011-04-19

来源:互联网

灵感来自http://www.matrix67.com/blog/archives/85
使用matplotlib绘制二维图形,使用contour来绘制方程,省去了手工计算的麻烦,解决思路参见
http://stackoverflow.com/questions/2484527/is-it-possible-to-plot-implicit-equations-using-matplotlib
效果:

作者: lockend   发布时间: 2011-04-19

  1. import numpy as np
  2. import matplotlib.pyplot as plt

  3. X = np.arange(-5.0, 5.0, 0.1)
  4. Y = np.arange(-5.0, 5.0, 0.1)
  5. x, y = np.meshgrid(X, Y)
  6. f = 17 * x ** 2 - 16 * np.abs(x) * y + 17 * y ** 2 - 225

  7. plt.figure()
  8. CS = plt.contour(x, y, f, 0, colors='r')

  9. plt.title(r'$17x^2-16|x|y+17y^2=255$')
  10. plt.show()
复制代码

作者: lockend   发布时间: 2011-04-19