在Python中使用MatPlotLib绘制散点图
作为一个刚在本周初开始学习Python的人,我有几个问题。我刚刚使用了“DeepWalk”包来提取3890x3890大小网络的节点值。该文件中有三列,如下所示:在Python中使用MatPlotLib绘制散点图,python,matplotlib,plot,Python,Matplotlib,Plot,作为一个刚在本周初开始学习Python的人,我有几个问题。我刚刚使用了“DeepWalk”包来提取3890x3890大小网络的节点值。该文件中有三列,如下所示: [ 3630 0.7031911 -0.0012102757 824 0.8523387 0.40063575 1219 0.73236656 0.005508532 3361 0.77815723 0.18705063 1556 0.7212675 -0.27076223 1042 0.8121597 0.2764353 ....
[
3630 0.7031911 -0.0012102757
824 0.8523387 0.40063575
1219 0.73236656 0.005508532
3361 0.77815723 0.18705063
1556 0.7212675 -0.27076223
1042 0.8121597 0.2764353
.... ......... .........]
等等
我想知道:
这些可能看起来像是基本问题,但当我阅读软件包本身的文档时,我只能找到与使用随机数据集绘制散点图有关的内容,而不是在文件中添加前缀。如有任何见解,将不胜感激。谢谢 我建议使用pandas软件包读取您的csv文件
import pandas as pd
import matplotlib.pyplot as plt
df = pd.read_csv(/path/to/csv/file, header=None) # assume you have no header in your file
x = df.iloc[:, 1] # this gets you the second column
y = df.iloc[:, 2] # this gets you the third column
# iloc takes form [row, column], so : is taking all rows
plt.scatter(x, y)
plt.show()
这应该能起到作用,我希望能有所帮助 你的问题需要更具体一点。您是否已经将数据作为数组保存?您是否查看了
pyplot.scatter
文档以了解它所期望的输入?从现有阵列创建合适的对象时是否遇到问题?