我正在尝试编辑我的等高线图上的颜色条范围,从0到0.12,我已经尝试了一些方法,但是没有起作用。我一直把整个色带范围调到0.3,这不是我想要的。
这是我的代码:
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.tri as tri
triang = tri.Triangulation(x, y)
plt.tricontour(x, y, z, 15, colors='k')
plt.tricontourf(x, y, z, 15, cmap='Blues', vmin=0, vmax=0.12,\
extend ='both')
plt.colorbar()
plt.clim(0,0.12)
plt.ylim (0.5,350)
plt.xlim(-87.5,87.5)
plt.show()
x
、y
和z
都是具有一列和大量行的数组。你可以在这里看看我的图表:
发布于 2016-11-01 18:28:17
我认为这个问题确实是有道理的。@Fatma90:您需要提供一个工作示例,在您的案例中提供x,y,z。
无论如何,我们可以自己创造一些价值观。所以问题是,vmin和vmax被plt.tricontourf()
忽略了,我不知道有什么好的解决方案。
但是,这里有一个解决方法,手动设置levels
plt.tricontourf(x, y, z, levels=np.linspace(0,0.12,11), cmap='Blues' )
这里我们使用了10个不同的级别,看起来很不错(如果使用不同数量的级别,问题可能是有很好的刻度线)。
我提供了一个工作示例来查看效果:
import numpy as np
import matplotlib.pyplot as plt
#random numbers for tricontourf plot
x = (np.random.ranf(100)-0.5)*2.
y = (np.random.ranf(100)-0.5)*2.
#uniform number grid for pcolor
X, Y = np.meshgrid(np.linspace(-1,1), np.linspace(-1,1))
z = lambda x,y : np.exp(-x**2 - y**2)*0.12
fig, ax = plt.subplots(2,1)
# tricontourf ignores the vmin, vmax, so we need to manually set the levels
# in this case we use 11-1=10 equally spaced levels.
im = ax[0].tricontourf(x, y, z(x,y), levels=np.linspace(0,0.12,11), cmap='Blues' )
# pcolor works as expected
im2 = ax[1].pcolor(z(X,Y), cmap='Blues', vmin=0, vmax=0.12 )
plt.colorbar(im, ax=ax[0])
plt.colorbar(im2, ax=ax[1])
for axis in ax:
axis.set_yticks([])
axis.set_xticks([])
plt.tight_layout()
plt.show()
这就产生了
https://stackoverflow.com/questions/40338269
复制相似问题