2015-01-22 3 views
2

최소 및 최대 값을 보여주는 양쪽 끝에 레이블이있는 전체 캔버스에 걸쳐있는 가로형 색상 맵이 있습니다. 문제는 다른 최소값과 최대 값에 대해 라벨이 바깥쪽으로 스틱되어 이미지의 전체 크기가 변경된다는 것입니다. 이는 내가 원하지 않는 것입니다.matplotlib의 색상 막대 레이블 정렬

이 문제를 해결하기 위해 왼쪽 (이미지에서 -40000)의 라벨을 왼쪽으로, 오른쪽 (이미지에서 40000)의 라벨을 오른쪽으로 정렬하려고했으나 그것을하기 위해.

제 질문은 간단히 말해서, 색상 막대의 레이블 정렬을 어떻게 변경합니까? enter image description here

+1

당신이 당신의 코드를 게시 할 수 있습니다 –

+0

https://www.mail-archive.com/matplotlib-users @ lists.sourceforge.net/msg07447.html –

답변

6

이것은 당신이 시작할 수 있어야합니다

import matplotlib.pyplot as plt 
import numpy as np 

# some random data to plot 
x = np.random.rand(10,10)*80e3 - 40e3 
plt.imshow(x, aspect='auto', vmin=-40e3, vmax=40e3) 

# create the colorbar 
cb = plt.colorbar(orientation='horizontal', ticks=[-40e3,0,40e3]) 

# get the xtick labels 
tl = cb.ax.get_xticklabels() 

# set the alignment for the first and the last 
tl[0].set_horizontalalignment('left') 
tl[-1].set_horizontalalignment('right') 

plt.show() 

결과 :

enter image description here