我需要一些新鲜的眼睛。我正在尝试使用列表x和y中的值绘制散点图
尽管我有一个df.plot.scatter(“x”,“y”)的x和y值列表,但运行代码时会出现一个错误,指出
TypeError: scatter() missing 1 required positional argument: 'y'
我不知道我错过了什么。任何帮助都将不胜感激
from matplotlib import pyplot as plt
import pandas as pd
from pandas import DataFrame
#sample lists
hole_ID = ["A", "B", "C", "D", "E", "F"]
x = [1, 2, 4, 6, 4, 6]
y = [1, 5, 3, 3, 9, 6]
# Assign Drill_hole ID as Key, all other lists as values
dict_database = dict(zip(hole_ID, zip(x, y)))
# Create Dataframe and assign dict_database to it
df = DataFrame
pd.DataFrame.from_dict(dict_database, orient='index', columns=["x", "y"])
# Create and display Scatterplot
scatter1 = df.plot.scatter("x", "y")
plt.show()
我认为你犯了一个错误,忘记了定义df:
结果:
相关问题 更多 >
编程相关推荐