2016-10-24 6 views
0

컬러 맵을 표시하고 싶은 패치 컬렉션이 있습니다. 컬러 맵 위에 어떤 조작을했기 때문에 matplotlib.colorbar 인스턴스를 사용하여 정의 할 수 없습니다. 적어도 내가 말할 수있는 한 멀지 않았다. 어떤 작품matplotlib의 크기 설정 ColorbarBase 객체

cmap = matplotlib.cm.YlOrRd 
colors = [cmap(n) if pd.notnull(n) else [1,1,1,1] 
      for n in plt.Normalize(0, 1)([nullity for _, nullity in squares])] 

# Now we draw. 
for i, ((min_x, max_x, min_y, max_y), _) in enumerate(squares): 
    square = shapely.geometry.Polygon([[min_x, min_y], [max_x, min_y], 
             [max_x, max_y], [min_x, max_y]]) 
    ax0.add_patch(descartes.PolygonPatch(square, fc=colors[i], 
        ec='white', alpha=1, zorder=4)) 

그래서 내가 대신 matplotlib.colorbar.ColorbarBase 인스턴스를 정의 :

: 예를 들어, 결과

matplotlib.colorbar.ColorbarBase(ax1, cmap=cmap, orientation='vertical', 
           norm=matplotlib.colors.Normalize(vmin=0, vmax=1)) 

을하고 그래서 밖으로 빈 패치 데이터 부족 내 색상과는 약간의 조작을 제거합니다

enter image description here

내가 가지고있는 문제는이 컬러 바의 크기를 줄이려는 것입니다 (구체적으로는 sp ecific 수직 크기, 말하자면, 500 픽셀),하지만이 일을 명백한 방법을 참조하십시오. colorbar 인스턴스가있는 경우 axis property arguments을 사용하여 쉽게 조정할 수 있지만 ColorbarBase에는 이러한 인스턴스가 없습니다. 상기 참고 용

:

답변

1

크기와 모양은 축으로 정의됩니다. 이 코드는 2 개의 그림을 함께 그룹화하고 맨 위에 독립적으로 색상 막대를 추가하는 코드입니다. 크기가있다 줄이기 위해

cax = fig.add_axes([0.125, 0.925, 0.775, 0.0725]) #has to be as a list - starts with x, y coordinates for start and then width and height in % of figure width 
norm = mpl.colors.Normalize(vmin = low_val, vmax = high_val)  
mpl.colorbar.ColorbarBase(cax, cmap = self.cmap, norm = norm, orientation = 'horizontal') 
+0

년 Colorbar가 주어진 전체'axis'을 차지하기 위해 나타납니다, 그래서 유일한 방법 : 나는 나를 위해 일한 크기를 가지고 때까지이 인스턴스를 add_axes의 값으로 연주 '축'의 크기를 줄이십시오. 이것은 실제로 그렇게하는 가장 쉬운 방법입니다. 감사! –