【问题标题】:Plotting multiple graphs in one figure instead of in multiple figures [duplicate]在一个图中而不是在多个图中绘制多个图[重复]
【发布时间】:2020-04-28 10:12:51
【问题描述】:

我试图在一张图中绘制三个文件中的数据。截至目前,我尝试只做两个文件。它们都被绘制成图表,但在两个不同的数字中。 我希望它们出现在一个图形/图形/窗口中。

如果我需要在不降级的情况下更新问题的任何部分,请告诉我。我真的很感激。我愿意接受任何建议。非常感谢!

样本数据 1:

20190601T034207 NAME    cc130.aa.bb NAME-7600816.2005   1   1   NAME-37x161 37x161  d39c13  2821    0   0ce000  1283 JOBS/NAME-7600816.2005/blast-37-161.txt
20190601T034214 NAME    cc128.aa.bb NAME-7600816.2004   1   1   NAME-37x161 37x161  d39c13  2815    0   0ce000  1283 JOBS/NAME-7600816.2004/blast-37-161.txt
20190601T034208 NAME    nn019.aa.bb NAME-7600816.2008   1   1   NAME-37x161 37x161  d39c13  3465    0   0ce000  1283 JOBS/NAME-7600816.2008/blast-37-161.txt
20190601T034220 NAME    nn058.aa.bb NAME-7600816.2010   1   1   NAME-37x161 37x161  d39c13  3462    0   0ce000  1283 JOBS/NAME-7600816.2010/blast-37-161.txt
20190601T034217 NAME    nn011.aa.bb NAME-7600816.2014   1   1   NAME-37x161 37x161  d39c13  3469    0   0ce000  1283 JOBS/NAME-7600816.2014/blast-37-161.txt
20190601T034219 NAME    nn224.aa.bb NAME-7600816.2015   1   1   NAME-37x161 37x161  d39c13  3468    0   0ce000  1283 JOBS/NAME-7600816.2015/blast-37-161.txt

更新:

def file_processing (file_name, scatter_color, ax):
    ax.scatter(x,y, s=4, c=scatter_color, label=file_name)
if args.File1:
    file1=args.File1
    fig = plt.figure(figsize=(12.80,9.60),dpi=100)
    ax = fig.add_subplot(1,1,1)
    file_processing(file1, "blue", ax)

    if args.File2:
        file2=args.File2
        fig = plt.figure(figsize=(12.80,9.60),dpi=100)
        ax = fig.add_subplot(1,1,1)
        file_processing(file2, "green",ax)

        if args.File3:
            file3=args.File3
            fig = plt.figure(figsize=(12.80,9.60),dpi=100)
            x = fig.add_subplot(1,1,1)
            file_processing(file3, "red",ax)

【问题讨论】:

    标签: python matplotlib plot scatter


    【解决方案1】:

    您需要将axfile_processing 函数中取出并输入参数,如下所示:

    def file_processing (file_name, scatter_color, ax):
    
        #  Move these 2 out of here:
        #  fig = plt.figure(figsize=(12.80,9.60),dpi=100)
        #  ax = fig.add_subplot(1,1,1)
    
    
    if args.File1:
    
        # Put it here:
        fig = plt.figure(figsize=(12.80,9.60),dpi=100)
        ax = fig.add_subplot(1,1,1)
    
        file_processing(file1, "blue", ax)
    

    更新,完整解决方案

    def file_processing (file_name, scatter_color, ax):
        ax.scatter(x,y, s=4, c=scatter_color, label=file_name)
    
    
    if args.File1:
        file1=args.File1
        fig = plt.figure(figsize=(12.80,9.60),dpi=100)
        ax = fig.add_subplot(1,1,1)
        file_processing(file1, "blue", ax)
    
        if args.File2:
            file2=args.File2
            file_processing(file2, "green",ax)
    
            if args.File3:
                file3=args.File3
                file_processing(file3, "red",ax)
    

    【讨论】:

    • 以下是应该的样子吗?如果是,它仍然向我显示两个数字。此外,另一个用户提供的链接没有回答我的问题。你知道我怎么联系他让他知道吗? (在我上面的问题末尾添加了新代码)
    • 不,您只需要创建一次figax 然后重复使用它,或者每次添加另一个系列时绘制到相同的轴。我用完整的解决方案更新了我的答案。
    • 谢谢,它正在工作。如果可以的话,你能看看我的另一篇文章吗?我还想知道如何修复 x 轴刻度。我想指定它从哪一天开始和在哪一天结束。如果你不熟悉它,这一切都很好,我会再试一次。再次感谢 链接到我的其他问题:link
    • 如果你有时间可以请你投票这个问题吗?如果您喜欢在整个过程中提供帮助,以防万一。谢谢
    猜你喜欢
    • 2021-04-06
    • 1970-01-01
    • 2021-09-23
    • 1970-01-01
    • 2021-02-13
    • 1970-01-01
    • 1970-01-01
    • 2013-10-03
    • 2021-04-21
    相关资源
    最近更新 更多