绘制散点图

时间:2020-04-01 16:33:25

标签: python pandas numpy

House_prices = [10050, 42300, 50206, 105000, 22350]
Num_rooms = [4, 5, 6, 10, 12, 2]

code

#This is the code that I have tried:
x = df.House_prices
y = df.Num_rooms
plt.scatter(x,y)
plt.show()

我想将"House_prices""Num_rooms"绘制成散点图。但是我遇到了此错误'list' object has no attribute 'House_prices' 我不知道出什么问题了,我需要一些帮助来找出出什么问题了。我错了哪一部分?是上半部分:"x = df.House_prices" and "y = df.Num_rooms"吗?

1 个答案:

答案 0 :(得分:0)

因此,首先创建一个x轴数组或列表。我为此使用了numpy。

import numpy as np
x = np.arange(0,len(House_Prices),1)
x1 = np.arange(0, len(Num_rooms),1)

fig=plt.figure()
ax = fig.add_axes([0,0,1,1])
ax.scatter(x,House_Prices)
ax.scatter(x1,Num_rooms)
plt.yscale(value='log')
plt.ylim(0.5,1e5)
plt.show()