2013-07-22 74 views
2

我試圖設置使用contour()生成的圖的x和y軸的值,但當前無法從軸讀取特定值desried。在不使用xticks的情況下設置2D輪廓圖的軸值

fid_list = [] 
for fidN in arange(frames): 
    offset = fidN * fid_pts 
    current_fid = cmplx_data[offset:offset+fid_pts] 
    fid_list.append(current_fid) 

fid_mat = fid_list 
jres_spec = abs(fftshift(fft2(fid_mat))) 
max_val = jres_spec.max()/15 
min_val = max_val*0.15 
steps = 40 
figure() 
CS=contour(jres_spec,arange(min_val,max_val,(max_val-min_val)/steps)) 
show() 

產生這樣

enter image description here 此前我一直使用xticks和yticks被設置軸的值,但現在對劇情的確切位置已經成爲重要的情節,所以是能夠讀取軸上的值將是非常有用的,我不能用x/yticks做。

當繪製一維譜,我用下面的公式,使我能夠讀出x軸

bins = arange(828, -196, -1) #change this so that 0 value occurs at value it's meant to 
x = (2000 * bins/1024.0)/128.0 
plot(x, fftshift(fft(fid_list[0]))) 
plt.gca().invert_xaxis() 
show() 

而且將同樣使用這個對我的2D等高線圖的y軸

ybins = arange(15, -15, -1) 
y = ybins * ((1/(15*10^(-3)))/ 30.0) 

但我有麻煩這個融入我的代碼...

我使用這樣的事情

嘗試
ybins = arange(15, -15, -1) 
y = ybins * ((1/(15*10^(-3)))/ 30.0) 
xbins = arange(828, -196, -1) 
x = (2000 * xbins/1024.0)/128.0 

fid_mat = fid_list 
jres_spec = abs(fftshift(fft2(fid_mat))) 
max_val = jres_spec.max()/15 
min_val = max_val*0.15 
steps = 40 
figure() 
CS=contour((x, y, jres_spec),arange(min_val,max_val,(max_val-min_val)/steps)) 
show() 

其返回

--------------------------------------------------------------------------- 
TypeError         Traceback (most recent call last) 
/home/dominicc/<ipython-input-34-28b34c6c069d> in <module>() 
     7 bins = arange(828, -196, -1) #change this so that 0 value occurs at value it's meant to 
     8 x = (2000 * bins/1024.0)/128.0 
----> 9 CS=contour((x_list, jres_spec),arange(min_val,max_val,(max_val-min_val)/steps)) 
    10 show() 

/usr/lib/pymodules/python2.7/matplotlib/pyplot.pyc in contour(*args, **kwargs) 
    2195   ax.hold(hold) 
    2196  try: 
-> 2197   ret = ax.contour(*args, **kwargs) 
    2198   draw_if_interactive() 
    2199  finally: 

/usr/lib/pymodules/python2.7/matplotlib/axes.pyc in contour(self, *args, **kwargs) 
    7379   if not self._hold: self.cla() 
    7380   kwargs['filled'] = False 
-> 7381   return mcontour.QuadContourSet(self, *args, **kwargs) 
    7382  contour.__doc__ = mcontour.QuadContourSet.contour_doc 
    7383 

/usr/lib/pymodules/python2.7/matplotlib/contour.pyc in __init__(self, ax, *args, **kwargs) 
    1110   are described in QuadContourSet.contour_doc. 
    1111   """ 
-> 1112   ContourSet.__init__(self, ax, *args, **kwargs) 
    1113 
    1114  def _process_args(self, *args, **kwargs): 

/usr/lib/pymodules/python2.7/matplotlib/contour.pyc in __init__(self, ax, *args, **kwargs) 
    701   if self.origin == 'image': self.origin = mpl.rcParams['image.origin'] 
    702 
--> 703   self._process_args(*args, **kwargs) 
    704   self._process_levels() 
    705 

/usr/lib/pymodules/python2.7/matplotlib/contour.pyc in _process_args(self, *args, **kwargs) 
    1123    self.zmax = args[0].zmax 
    1124   else: 
-> 1125    x, y, z = self._contour_args(args, kwargs) 
    1126 
    1127    x0 = ma.minimum(x) 

/usr/lib/pymodules/python2.7/matplotlib/contour.pyc in _contour_args(self, args, kwargs) 
    1167   if Nargs <= 2: 
    1168    z = ma.asarray(args[0], dtype=np.float64) 
-> 1169    x, y = self._initialize_x_y(z) 
    1170    args = args[1:] 
    1171   elif Nargs <=4: 

/usr/lib/pymodules/python2.7/matplotlib/contour.pyc in _initialize_x_y(self, z) 
    1230   ''' 
    1231   if z.ndim != 2: 
-> 1232    raise TypeError("Input must be a 2D array.") 
    1233   else: 
    1234    Ny, Nx = z.shape 

TypeError: Input must be a 2D array. 

現在我努力想其他辦法,我可以做到這一點。

任何意見/建議?

回答

1

您可以通過取出多餘的括號中調用contour擺脫錯誤的:

CS=contour(x, y, jres_spec,arange(min_val,max_val,(max_val-min_val)/steps)) 

如果不給你你想要的陰謀,試圖xlimylim以設置軸直接限制。

相關問題