肯定我缺少明显的东西,但我不太喜欢Matplotlib在本示例结尾为我创建的颜色栏
import matplotlib.pyplot as plt
import numpy as np
x = np.arange(50)
xy = x*x[:,None]/200 # 0.000 to 12.005
plt.contourf(xy, levels=100)
plt.contour(xy,levels=12, colors='black').clabel(inline=1, fmt='%.2f')
plt.colorbar()
答案 0 :(得分:4)
请尝试更改轮廓的顺序,因为plt
将捕获最新的对象,并且具有12个级别的轮廓没有颜色:
import matplotlib.pyplot as plt
import numpy as np
x = np.arange(50)
xy = x*x[:,None]/200 # 0.000 to 12.005
plt.contour(xy, levels=12, colors='black').clabel(inline=1, fmt='%.2f')
plt.contourf(xy, levels=100)
plt.colorbar()
或:,您可以将所需的轮廓直接传递到plt.colobar()
:
...
c = plt.contourf(xy, levels=100)
plt.contour(xy, levels=12, colors='black').clabel(inline=1, fmt='%.2f')
plt.colorbar(c)
具有相同级别值:
...
plt.contour(xy, levels=12, colors='black').clabel(inline=1, fmt='%.2f')
plt.contourf(xy, levels=12)
plt.colorbar()