【问题标题】:Plot curve equation without solving for dependent variable in matplotlib? [duplicate]绘制曲线方程而不求解matplotlib中的因变量? [复制]
【发布时间】:2017-06-21 17:52:57
【问题描述】:

如果我想绘制类似y=x^2 的东西,那么我可以做类似的事情

x = np.linspace(-10, 10, 1000)
plt.plot(x, x**2)

但是,如果等式类似于x + y + sin(x) + sin(y) = 0,我该怎么办?我宁愿不必手动解决y。有没有处理这个的函数?

【问题讨论】:

    标签: python matplotlib


    【解决方案1】:

    这样就可以了:

    import matplotlib.pyplot
    import numpy as np
    X, Y = np.meshgrid(np.arange(-10, 10, 0.05),np.arange(-10, 10, 0.05))
    matplotlib.pyplot.contour(X, Y, X + Y + np.sin(X) + np.sin(Y), [0])
    matplotlib.pyplot.show()
    

    【讨论】:

      【解决方案2】:

      你可以试试等高线图:

      from matplotlib.pyplot import *
      
      def your_function(x, y):
          return 5 * np.sin(x) - 2 * np.cos(y)
      
      x = np.linspace(-10, 10, 1000)
      X, Y = np.meshgrid(x, x)
      Z = your_function(X, Y)
      
      CP = contour(X, Y, Z, [0])
      grid()
      show()
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-08-16
        • 1970-01-01
        • 1970-01-01
        • 2017-04-24
        • 1970-01-01
        • 2013-01-20
        相关资源
        最近更新 更多