绘制散点图

2024-05-15 01:30:51 发布

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

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"


Tags: thedfthatishaveshowcodeplt
1条回答
网友
1楼 · 发布于 2024-05-15 01:30:51

因此,首先创建一个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()

相关问题 更多 >

    热门问题