2011-12-08 8 views
1

コンターレベルを値のログでスケールしてコンタープロットを作成しようとしています。ただし、カラーバーの隣には十分な値が表示されません。ここに簡単な例があります。LogNorm()を使用しているときにカラーバーに値が表示されない

import numpy as N 
import matplotlib as M 
import matplotlib.pyplot as PLT 

# Set up a simple function to plot 
values = N.empty((10,10)) 
for xi in range(10): 
    for yi in range(10): 
     values[xi,yi] = N.exp(xi*yi/10. - 1) 

levels = N.logspace(-1, 4, 10) 
log_norm = M.colors.LogNorm() 
# Currently not used - linear scaling 
linear_norm = M.colors.Normalize() 

# Plot the function using the indices as the x and y axes 
PLT.contourf(values, norm=log_norm, levels=levels) 
PLT.colorbar() 

contourf呼び出しでlog_normをlinear_normに切り替えると、カラーバーに値があることがわかります。もちろん、linear_normを使用すると、色は線形にスケーリングされ、輪郭はこの関数でうまく分散されません。

私は、Mac OS 10.7で、matplotlibに付属のpython 2.7.2、enthought版を使用しています。

答えて

3

PLT.colorbarへの呼び出しにフォーマットを追加します。

import numpy as N 
import matplotlib as M 
import matplotlib.pyplot as PLT 

# Set up a simple function to plot 
x,y = N.meshgrid(range(10),range(10)) 
values = N.exp(x*y/10. - 1) 

levels = N.logspace(-1, 4, 10) 
log_norm = M.colors.LogNorm() 
# Currently not used - linear scaling 
linear_norm = M.colors.Normalize() 
# Plot the function using the indices as the x and y axes 
PLT.contourf(values, norm=log_norm, levels=levels) 
PLT.colorbar(format='%.2f') 
PLT.show() 

enter image description here

+0

ありがとうございました!これはまさに私が探していたものです。 – Brandt

関連する問題