简体   繁体   English

Matplotlib图大小选项分割图

[英]Matplotlib Figure Size Option Splitting the plots

I am trying to plot a reference file (A_B_0) and 5 other associated files (A_B_1, A_B_2....A_B_5) in the same plot. 我正在尝试在同一图中绘制参考文件(A_B_0)和其他5个相关文件(A_B_1,A_B_2 .... A_B_5)。 My X-axis will be same but I will have variations in Y-coordinates. 我的X轴相同,但我的Y坐标会有变化。 My issue is when I am trying to use the plt.figure(figsize=()) option, it is plotting all of them as individual plots. 我的问题是,当我尝试使用plt.figure(figsize =())选项时,它会将所有图绘制为单独的图。 So, instead of getting 1 plot, I am getting 5 individual plots with (A_B_0 and A_B_1), (A_B_0 and A_B_2).....(A_B_0 and A_B_5). 因此,我得到的不是5个地块,而是(A_B_0和A_B_1),(A_B_0和A_B_2).....(A_B_0和A_B_5)。 Any help on fixing this issue would be really appreciated. 任何解决此问题的帮助将不胜感激。

    import pandas as pd
    import numpy as np
    import matplotlib.pyplot as plt
    %matplotlib notebook
    filelist=[]
    for i in range (1,6):
        filelist.append("/Users/Hrihaan/Desktop/A_B_%s.txt" %i)
    for fname in Filelist:
        data= pd.read_table(fname, dtype=float, header=None, sep='\s+').values
        data1= pd.read_table('/Users/Hrihaan/Desktop/A_B_0.txt', dtype=float, header=None, sep='\s+').values
        x=np.arange(1,100, 1)
        y=data[:,2]
        y1=data1[:,2]
        plt.plot(x,y)
        plt.plot(x,y1)
        plt.figure(figsize=(10,5))
        plt.show()

Try this. 尝试这个。 I'm not sure it will work. 我不确定是否可以。 I cannot test this code. 我无法测试此代码。

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
%matplotlib notebook
filelist=["/Users/Hrihaan/Desktop/A_B_%s.txt"%i for i in range (1,6) ]
plt.figure(figsize=(10,5))
x=np.arange(1,100, 1)
data1= pd.read_table('/Users/Hrihaan/Desktop/A_B_0.txt', dtype=float, header=None, sep='\s+').values
y1=data1[:,2]
plt.plot(x,y1)
for fname in Filelist:
   data= pd.read_table(fname, dtype=float, header=None, sep='\s+').values
   y=data[:,2]
   plt.plot(x,y)
plt.show()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM