使用 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()
如果您在轮廓函数调用中将 log_norm 切换为 Linear_norm,您将看到颜色条确实有值。当然,使用 Linear_norm 意味着颜色是线性缩放的,并且该函数的轮廓分布不均匀。
我正在 Mac OS 10.7 上使用 python 2.7.2,即 matplotlib 附带的 enthought 版本。
I am trying to make a contour plot with the contour levels scaled by the log of the values. However, the colorbar does not show enough values next to the colors. Here is a simple example.
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()
If you switch log_norm for linear_norm in the contourf call, you'll see that the colorbar does have values. Of course, using linear_norm means the colors are scaled linearly and the contours are not well distributed for this function.
I'm using python 2.7.2, enthought edition which comes with matplotlib, on Mac OS 10.7.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
向
PLT.colorbar
的调用添加格式:Add a format to the call to
PLT.colorbar
: