python - 散点图不访问 y 值数据(Python)
问题描述
我需要一些新鲜的眼睛。我正在尝试使用列表 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是一个错误:
df=pd.DataFrame.from_dict(dict_database, orient='index', columns=["x", "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=pd.DataFrame.from_dict(dict_database, orient='index', columns=["x", "y"])
# Create and display Scatterplot
scatter1 = df.plot.scatter("x", "y")
plt.show()
推荐阅读
- acumatica - PXSelector 属性抑制表单上的错误
- android - 如何在使用改造 android 发布数据后移动到另一个活动?
- java - 使用 Java 的 keycloak 离线令牌
- capl - 属于同一测试节点的特定测试用例组的测试报告拆分
- mysql - MySQL:通过 Node.js 中的存储过程保存 JSON 数据
- python - 当一个是部分的时覆盖两个 Pandas DataFrame
- c# - 如何通过id(主键)winforms删除listView中的选定项目
- java - Hibernate 错误,SQLGrammarException 的原因是什么
- elasticsearch - 某些属性或可参数化文件中的 Logstash Input -> JDBC?
- angular - 离子 5 连接本地主机 api