2012-09-12 70 views
1

我可以生成這樣的hexbin圖(代碼從http://matplotlib.org/examples/pylab_examples/hexbin_demo.html截取)是否可以在matplotlib hexbin圖中命名x和y軸?

import numpy as np 
import matplotlib.cm as cm 
import matplotlib.pyplot as plt 

n = 100000 
x = np.random.standard_normal(n) 
y = 2.0 + 3.0 * x + 4.0 * np.random.standard_normal(n) 
xmin = x.min() 
xmax = x.max() 
ymin = y.min() 
ymax = y.max() 

plt.subplots_adjust(hspace=0.5) 
plt.subplot(121) 
plt.hexbin(x,y, cmap=cm.jet) 
plt.axis([xmin, xmax, ymin, ymax]) 
plt.title("Hexagon binning") 
cb = plt.colorbar() 
cb.set_label('counts') 

plt.subplot(122) 
plt.hexbin(x,y,bins='log', cmap=cm.jet) 
plt.axis([xmin, xmax, ymin, ymax]) 
plt.title("With a log color scale") 
cb = plt.colorbar() 
cb.set_label('log10(N)') 

plt.show() 

是否有任何方式來標記x和與軸名稱hexbin的y軸?我想讓「x-label」在x軸數字下顯示,「ylabel」顯示在y軸數字的左側。這是除了彩條上的標籤外。

+0

'plt.xlabel( 'X標籤')','plt.ylabel( 'ylabel')'? – aland

+0

工作!回答和生病接受? – vasek1

回答

1

您可以使用xlabelylabel matplotlib命令:

plt.xlabel('x-label') 
plt.ylabel('y-label') 
相關問題