python中的散点图和散点线

2024-04-25 10:10:55 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个关于如何将散点图和线正确地放置到一个图中的问题。你知道吗

代码如下:

import numpy as np
import matplotlib.pyplot as plt

t= np.linspace(60, 180,100)
ax= plt.subplot()
ax.plot(data.Weight, data.Height , color = 'red')
ax.plot(t, 60+ 0.05*t, label=r"$Height = 60+ 0.05*Weight$")
ax.plot(t, 50+ 0.16*t, label=r"$Height = 50+ 0.16*Weight$")
ax.set_xlabel(r'$Weight$', fontsize=12)
ax.set_ylabel(r'$Height$', fontsize=12)
ax.set_title('Dependence')

plt.show()

enter image description here

可以看到散点图反射不正确(显示为线)

谢谢你!你知道吗


Tags: 代码importnumpydataplotmatplotlibasnp
2条回答

{假设要在cd1中显示变量^}

ax.scatter(data.Weight, data.Height , color = 'red')

data.Weight分散在data.Height上:

ax.plot(data.Weight, data.Height , 'o', markerfacecolor = 'red')

相关问题 更多 >