简体   繁体   English

绘制散点图

[英]plotting a scatter plot

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()

I want to plot "House_prices" and "Num_rooms" into a scatter plot.我想将"House_prices""Num_rooms"绘制成散点图。 But I encountered this error 'list' object has no attribute 'House_prices' I don't know whats wrong and I need some help to find out what is wrong.但是我遇到了这个错误'list' object has no attribute 'House_prices'我不知'list' object has no attribute 'House_prices'什么问题,我需要一些帮助才能找出问题所在。 Which part am I wrong?我错了哪一部分? is it the top half: "x = df.House_prices" and "y = df.Num_rooms" ?它是上半部分: "x = df.House_prices" and "y = df.Num_rooms"吗?

So, first create a x-axis array or list.因此,首先创建一个 x 轴数组或列表。 I used numpy for that.我为此使用了 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()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM