【问题标题】:how to create coordinate [x,y] with two list (for a scatter plot, matplotlib)如何使用两个列表创建坐标 [x,y](对于散点图,matplotlib)
【发布时间】:2021-02-25 18:17:49
【问题描述】:

这里是初学者。在我们的遗传课程中,我们被要求使用 Excel 来创建绘图,但我想用 Python 来做。当我尝试绘制散点图时,我得到x=y 行。我认为我必须将我的数据设置为坐标

 data = [
    [1, 2],
    [3, 2],
    [4, 7],
    [2, 4],
    [...],
    ]

    x, y = zip(*data)
    plt.scatter(x, y)
    plt.show() 

如其他地方所示。但我正在努力做到这一点。

我暂时这样做了,但我不知道如何将这两个列表用作[x, y] 然后进行绘图。

import pandas as pd
import matplotlib.pyplot as plt

def read_csvfile(file):
    df = pd.read_csv(file, sep=';', header=0)
    return df
   
cal = read_csvfile('Genotypage_BCM2531_snp49.csv')
x = cal['Signal_FAM']
y = cal['Signal_VIC']

plt.scatter(x, y)
plt.show() 

但我想要坐标簇 [x,y],它应该是这样的:

【问题讨论】:

  • 尝试将decimal=',' 添加到read_csv 调用中。

标签: python matplotlib scatter-plot


【解决方案1】:

我想你想要:

x,y = list(zip(*data))

plt.scatter(x,y)

输出:

【讨论】:

  • 正如 BigBen 指出的那样,我只需要在 read_csv 调用中添加 decimal=',' 就可以了。但是谢谢,很高兴知道我可以使用 list(zip(*data))
猜你喜欢
  • 1970-01-01
  • 2015-09-28
  • 1970-01-01
  • 1970-01-01
  • 2021-03-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多