2015-01-25 4 views
0

파이썬 2.7을 사용 중이며 간단한 컬러 막대를 만들고 싶습니다.matplotlib를 사용하여 파이썬에서 컬러 막대를 플로팅 할 때 오류가 발생했습니다.

import matplotlib.pylab as plt 
import matplotlib as mpl 

redgreendict = {'red':[(0.0, 1.0, 1.0), (0.5, 1.0, 1.0) ,(1.0, 0.0, 0.0)], 
       'green':[(0.0, 0.0, 0.0), (0.5, 1.0, 1.0), (1.0, 1.0, 1.0)], 
       'blue':[(0.0, 0.2, 0.0), (0.5, 1.0, 1.0), (1.0, 0.2, 0.0)]} 

fig = plt.figure() 
ax1 = fig.add_axes([0.05, 0.08, 0.9, 0.08]) 
cmap = mpl.colors.LinearSegmentedColormap('redgreen', redgreendict, 1000) 

cb1 = mpl.colorbar.ColorbarBase(ax1, cmap, orientation='vhorizontal') 

그리고이 오류 메시지가 얻을 : 내가하고 있어요 것은 이것이다 나는 문제가 matplotlib.colorbar.ColorbarBase의 방향 부분에 낳는 것을 가정

File "figutils_used_one.py", line 1208, in make_europe_graph 
cb1 = matplotlib.colorbar.ColorbarBase(ax1, cmap, orientation='vhorizontal') 

File "C:\Anaconda\lib\site-packages\matplotlib\colorbar.py", line 320, in __init__ 
self.config_axis() 

File "C:\Anaconda\lib\site-packages\matplotlib\colorbar.py", line 360, in config_axis 
ax.xaxis.set_label_position(self.ticklocation) 

File "C:\Anaconda\lib\site-packages\matplotlib\axis.py", line 1728, in set_label_position 
assert position == 'top' or position == 'bottom' 

AssertionError 

합니다. 나는 주변을 둘러 보았고 파이톤 (Pythton) 버전의 문제 일 수도있다. vhorizontal 대신 vertical, v, h을 인수에 넣으려고 시도했지만 아무래도 아무 일도 일어나지 않습니다.

+1

모두'CB1 = matplotlib.colorbar.ColorbarBase (AX1, cmap를, 방향 = '수직') '와'cb1 = matplotlib.colorbar.ColorbarBase (ax1, cmap, orientation = 'horizontal')'나를 위해 일한다. – plonser

+0

나는 그것을 풀었다. 문제는 matplotlib.colorbar.ColorbarBase에서 "norm = matplotlib.colors.Normalize (0,1)."규범을 구현해야한다는 것이 었습니다. 이 일을 할 때 모든 일이 어떤 이유로 든 잘됩니다. –

답변

0

이 코드는 나를 위해 작동 :

import matplotlib.pylab as plt 
import matplotlib as mpl 

min_val = -1 
max_val = 1 

redgreendict = {'red':[(0.0, 1.0, 1.0), (0.5, 1.0, 1.0) ,(1.0, 0.0, 0.0)], 
       'green':[(0.0, 0.0, 0.0), (0.5, 1.0, 1.0), (1.0, 1.0, 1.0)], 
       'blue':[(0.0, 0.2, 0.0), (0.5, 1.0, 1.0), (1.0, 0.2, 0.0)]} 

cmap = mpl.colors.LinearSegmentedColormap('redgreen', redgreendict, 1000) 
norm = mpl.colors.Normalize(min_val, max_val) 

fig = plt.figure() 
ax1 = fig.add_axes([0.05, 0.08, 0.9, 0.08]) 

cb1 = mpl.colorbar.ColorbarBase(ax1, cmap, norm=norm, orientation='horizontal') 

이 결과 :

plot

+0

예. 나는 똑같이했다. 규범을 도입 할 때 잘 작동합니다. –

관련 문제