问题
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:
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)
来源:https://stackoverflow.com/questions/59687130/plotting-multiple-graphs-in-one-figure-instead-of-in-multiple-figures