我想打印一些数据,但颜色栏高于绘图。我怎样才能解决这个问题
import numpy as np
import matplotlib.pyplot as plt
import scipy.interpolate
fig, ax = plt.subplots()
# Generate data:
x = np.linspace(1, 1, 10)
y = np.linspace(1,100, 10)
for i in range(10, 100, 10):
x = append(x, np.linspace(i, i, 10))
y = append(y, np.linspace(1, 100, 10))
z = numpy.random.uniform(-5, 5, size=100)
# Set up a regular grid of interpolation points
xi, yi = np.linspace(x.min(), x.max(), 100), np.linspace(y.min(), y.max(), 100)
xi, yi = np.meshgrid(xi, yi)
# Interpolate
rbf = scipy.interpolate.Rbf(x, y, z, function='linear')
zi = rbf(xi, yi)
s = ax.imshow(zi, vmin=z.min(), vmax=z.max(), origin='lower',
extent=[x.min(), x.max(), y.min(), y.max()])
plt.xlim([0,200])
#s = ax.scatter(x, y, c=z, marker = 's')
plt.colorbar(mappable=s, ax=ax)
plt.show()
最简单的解决方案(以您为例)是删除该行
但既然你把它放在那里,我想你真的想/需要它。因此,您必须手动调整颜色条的高度:
使用@MaxNoe建议的
shrink
参数colorbar
也可以达到目的。但你必须摆弄来获得正确的价值相关问题 更多 >
编程相关推荐