【问题标题】:What is the equation of this line in Python simple plot?Python简单图中这条线的方程是什么?
【发布时间】:2025-12-01 18:40:02
【问题描述】:

请帮我弄清楚这条线的方程式是什么:

import matplotlib.pyplot as plt
import numpy as np

#start, stop, num (* is args [positional], ** is kwargs[keyword])
x = np.linspace(0, 2*np.pi, 400)
y = np.sin(x ** 2)

#this closes *args
plt.close('all')

#one figure and one subplot
f, ax = plt.subplots()
ax.plot(x,y)
ax.set_title("simple plot")
plt.xlabel('x-axis')
plt.ylabel('y-axis')
plt.show()

代码运行,并返回一个图表,但我无法弄清楚图表的方程式是什么。请帮助我,如果你能解释一下代码做了什么来绘制这个方程。我对python很陌生。 :) 谢谢!

【问题讨论】:

  • 怎么不是 x 的平方从 0 到 2*pi 的正弦?
  • y = np.sin(x ** 2)。它在代码中。
  • 是不是有人给你代码,不解释类?

标签: python python-3.x plot graphing


【解决方案1】:

x**2 在 Python 中表示 x 的 2 次方。在其他编程语言中,它主要被标记为x^2。所以你的函数是y = sin(x*x)

【讨论】:

  • 非常感谢!很有帮助! :)
  • 在代码的 x = np.linspace(0, 2*np.pi, 400) 行中,这些是图形的参数吗?
  • @Ava np.linspace 是一个函数,它创建一个由 0 到 2 pi 的 400 个均匀间隔的浮点数组成的数组。
  • @Ava 如果答案对您有帮助,您会愿意通过单击左侧箭头下方的复选标记来接受答案吗?
最近更新 更多