0

I am trying to plot data from three files in only one figure. As of right now, I try to do only two files. They both gets graphed, but in two different figures. I want them to be in one graph/figure/window.

Please, let me know if I need to update any part of my question without downgrading it. I would really appreciate it. I am open to any suggestions. Thanks a lot!

Sample Data 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

UPDATE:

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)

1 Answers1

0

You need to pull out the ax out of the file_processing function and make in argument, something like this:

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)

Update, full solution

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)
andrzejwp
  • 922
  • 4
  • 11
  • Is the following what it is supposed to be like? If yes, it is still showing me two figures. Also, the links another user provided is not answering my questions. Do you know how I may get in touch with him to let him know? (Added new code at the end of my question above) –  Jan 10 '20 at 18:54
  • No, you only need to create the `fig` and `ax` once and then reuse it, or plot to the same axes every time you add another series. I updated my answer with full solution. – andrzejwp Jan 10 '20 at 19:01
  • Thanks, it is working. If possible, could you please check out my other post? I also want to know how I can fix the x-axis ticks. I want to specify what day it starts and what day it ends at. If you are not familiar with it, it is all good, I will try again on it. Thanks again Link to my other question: [link](https://stackoverflow.com/questions/59683965/plotting-three-scatter-plots-in-one-figure) –  Jan 10 '20 at 19:10
  • if you have time could you please upvote the question? It is in case if you enjoyed helping out through the process. Thanks –  Jan 17 '20 at 21:08