我对使用对数颜色缩放的等高线图有疑问。我想手动指定级别。然而,Matplotlib 以一种奇怪的方式绘制颜色条——标签放置得不好,只出现一种颜色。这个想法是基于 http://adversus.110mb.com/?cat=8
有没有人在那里,谁能帮助我?我使用最新的 git-repository matplotlib 版本,v1.1.0 (2011-04-21)
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.mlab import bivariate_normal
from matplotlib.colors import LogNorm
from matplotlib.backends.backend_pdf import PdfPages
delta = 0.5
x = np.arange(-3.0, 4.001, delta)
y = np.arange(-4.0, 3.001, delta)
X, Y = np.meshgrid(x, y)
Z = bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)
fig = plt.figure()
ax = fig.add_subplot(1,1,1)
#axim = ax.imshow(Z, norm = LogNorm())
axim = ax.contourf(X,Y,Z,levels=[1e0,1e-1,1e-2,1e-3],cmap=plt.cm.jet,norm = LogNorm())
cb = fig.colorbar(axim)
pp = PdfPages('fig.pdf')
pp.savefig()
pp.close()
plt.show()
非常感谢您的帮助!正如你所建议的那样,它工作得很好......但是,我还有一个问题:为什么 matplotlib 不允许我在对数模式下选择水平线的数量:
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.mlab import bivariate_normal
from matplotlib.colors import LogNorm
from matplotlib.backends.backend_pdf import PdfPages
delta = 0.5
x = np.arange(-3.0, 4.001, delta)
y = np.arange(-4.0, 3.001, delta)
X, Y = np.meshgrid(x, y)
Z = bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)
fig = plt.figure()
ax = fig.add_subplot(1,1,1)
#axim = ax.imshow(Z, norm = LogNorm())
#axim = ax.contourf(X,Y,Z,levels=[1e-3,1e-2,1e-1,1e0],cmap=plt.cm.jet,norm = LogNorm())
axim = ax.contourf(X,Y,Z,20,cmap=plt.cm.jet,norm = LogNorm())
cb = fig.colorbar(axim)
pp = PdfPages('fig.pdf')
pp.savefig()
pp.close()
plt.show()
http://i.stack.imgur.com/VeVFQ.png
这是我原来的问题...