2024-10-08 19:27:39 发布
网友
我有一些数据点,我用matplotlib绘制了散点图。现在我想在同一散点图上为方程x+y=0画一条线。 这就是最终的情节应该是什么样子。
我现在拥有的是这个。
如何将线x+y=0添加到此散点图
如果没有执行plt.show(),可以绘制多个内容
plt.show()
如果未指定变量作为图形,则打印的任何内容都将保存到不可见的空白图纸中,并在决定打印时显示
x = np.random.randint(1,100,10) y = np.random.randint(1,100,10) xx = np.arange(1,100) yy = -xx plt.scatter(x,y) plt.plot(xx,yy) plt.show()
你可以继续,直到你决定show()。这里的结果是:
show()
import numpy as np import matplotlib.pyplot as plt x = np.arange(-20,20)
您可以简单地执行以下操作:
plt.plot(x, -x)
或者,更一般地说:
def f(x): return -x plt.plot(x, f(x))
如果没有执行
plt.show()
,可以绘制多个内容如果未指定变量作为图形,则打印的任何内容都将保存到不可见的空白图纸中,并在决定打印时显示
你可以继续,直到你决定
show()
。这里的结果是:您可以简单地执行以下操作:
或者,更一般地说:
相关问题 更多 >
编程相关推荐