2012-07-24 95 views
0

我有負載配置文件數據,其中x軸是負載配置文件,使得對於多個相同的x值(恆定負載),我有不同的值爲y。 至今在Excel中我用線圖y和右鍵單擊graph->選擇素數據 - >通過提供它的範圍牛軸數據和經常給我圖形x軸重複值(加載配置文件)在matplotlib陰謀

Sample Chart

變化hoizontal軸數據我的問題是當我試圖給 plot(x,y)時,matplotlib爲y的唯一值繪製y圖形,即它忽略了對於相同的x值的所有剩餘值。 當我繪製陰謀(y)我得到序列號在x軸 我試圖檢查出xticks([0,5,10,15]),但無法獲得所需的結果。 我的問題是 是否有可能以類似的方式繪製一個圖形的excel 我可以想到的另一個替代方案是繪製情節(y和情節(x)與同一水平軸它至少給出了一個繪畫的想法,但是在那裏任何方式做到這一點excel的方式??

+0

向我們展示您的代碼,並告訴我們問題是什麼,而不是關於它的故事。 – Aesthete 2012-07-24 09:25:30

回答

0

從您的描述中,聽起來像是您想要使用「散點圖」繪圖命令而不是「繪圖」繪圖命令。這將允許使用多餘的x值。示例代碼:

import numpy as np 
import matplotlib.pyplot as plt 

# Generate some data that has non-unique x-values 
x1 = np.linspace(1,50) 
y1 = x1**2 
y2 = 2*x1 
x3 = np.append(x1,x1) 
y3 = np.append(y1,y2) 

# Now plot it using the scatter command 
# Note that some of the abbreviations that work with plot, 
# such as 'ro' for red circles don't work with scatter 
plt.scatter(x3,y3,color='red',marker='o') 

scatter plot

正如我在評論中所提到的,一些方便的「陰謀」快捷鍵不能用「分散」的工作,所以你可能要檢查的文件:http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.scatter

0

如果你想繪製y-values對於一個給定x-values,你需要得到具有相同的x值的指標。如果您正在使用numpy工作,那麼你可以嘗試

import pylab as plt 
import numpy as np 
x=np.array([1]*5+[2]*5+[3]*5) 
y=np.array([1,2,3,4,5]*3) 
idx=(x==1) # Get the index where x-values are 1 
plt.plot(y[idx],'o-') 
plt.show() 

如果您使用的是列表,您可以通過

# Get the index where x-values are 1 
idx=[i for i, j in enumerate(x) if j == 1] 
0

只是回答自己的問題,發現了這個,當我貼過這個問題,幾年前:)

def plotter(y1,y2,y1name,y2name): 
 
    averageY1=float(sum(y1)/len(y1)) 
 
    averageY2=float(sum(y2)/len(y2)) 
 
    fig = plt.figure() 
 
    ax1 = fig.add_subplot(111) 
 
    ax1.plot(y1,'b-',linewidth=2.0) 
 
    ax1.set_xlabel("SNo") 
 
    # Make the y2-axis label and tick labels match the line color. 
 
    ax1.set_ylabel(y1name, color='b') 
 
    for tl in ax1.get_yticklabels(): 
 
     tl.set_color('b') 
 
    ax1.axis([0,len(y2),0,max(y1)+50]) 
 
    
 
    ax2 = ax1.twinx() 
 
    
 
    ax2.plot(y2, 'r-') 
 
    ax2.axis([0,len(y2),0,max(y2)+50]) 
 
    ax2.set_ylabel(y2name, color='r') 
 
    for tl in ax2.get_yticklabels(): 
 
     tl.set_color('r') 
 
    plt.title(y1name + " vs " + y2name) 
 
    #plt.fill_between(y2,1,y1) 
 
    plt.grid(True,linestyle='-',color='0.75') 
 

 
    plt.savefig(y1name+"VS"+y2name+".png",dpi=200)