pyplot 在哪里定义级别数
我试图了解如何在轮廓工具链中创建级别、值、边界。
import matplotlib.pyplot as plt
import matplotlib as mpl
t=np.array([[-5,0,5,0,0,0],[0,0,5,0,0,0],[0,0,5,0,0,0],[5,5.2,10,5,5,0],
[0,0,5,0,0,0]], dtype=np.double)
print ("print as is")
print (t)
print ("appearing in a contourf as:")
print (np.flipud((t)))
# assuming indices: array[x,y]
# value 10 supposed to be at 0,0
# contourf's pos. x-axis is pointing up!!
xmin, xmax=-2, 3
ymin, ymax=-3, 1
fig, axs = plt.subplots(nrows=1, ncols=2)
ax0 = axs[0]
ax1 = axs[1]
# plot and add colorbar
set0 = ax0.contourf(t, extent=(xmin,xmax,ymin,ymax), cmap="brg")
#colorbar with coarse steps
cba = plt.colorbar(set0,ax=ax0)
# # This makes the colorbar "appear continuos"
# cba.boundaries=None
# cba.values = None
set0.changed()
# define colorbar and then plot
cNorm = mpl.colors.Normalize(vmin=np.min(t), vmax=np.max(t))
sm = mpl.cm.ScalarMappable(cNorm, cmap="brg")
cbb = plt.colorbar(sm,ax=ax1)
set1 = ax1.contourf(t, extent=(ymin,ymax,xmin,xmax), cmap="brg")
plt.show()
print("left .boundaries: {:s}".format(str(cba.boundaries)))
print("left ._boundaries: {:s}".format(str(cba._boundaries)))
print("right .boundaries: {:s}".format(str(cbb.boundaries)))
print("right len(._boundaries): {:s}".format(str(len(cbb._boundaries))))
对于左图,颜色条有 9 个边界和 8 个离散颜色值,右图有 257 个边界。 我对各种对象做了一些 vars(...) 和 dir(...) 。边界和价值的数量是在哪里做出的决定? 右图颜色条创建与默认行为的偏差是什么?
I'm trying to understand how levels, values, boundaries are created in the contourf-toolchain.
import matplotlib.pyplot as plt
import matplotlib as mpl
t=np.array([[-5,0,5,0,0,0],[0,0,5,0,0,0],[0,0,5,0,0,0],[5,5.2,10,5,5,0],
[0,0,5,0,0,0]], dtype=np.double)
print ("print as is")
print (t)
print ("appearing in a contourf as:")
print (np.flipud((t)))
# assuming indices: array[x,y]
# value 10 supposed to be at 0,0
# contourf's pos. x-axis is pointing up!!
xmin, xmax=-2, 3
ymin, ymax=-3, 1
fig, axs = plt.subplots(nrows=1, ncols=2)
ax0 = axs[0]
ax1 = axs[1]
# plot and add colorbar
set0 = ax0.contourf(t, extent=(xmin,xmax,ymin,ymax), cmap="brg")
#colorbar with coarse steps
cba = plt.colorbar(set0,ax=ax0)
# # This makes the colorbar "appear continuos"
# cba.boundaries=None
# cba.values = None
set0.changed()
# define colorbar and then plot
cNorm = mpl.colors.Normalize(vmin=np.min(t), vmax=np.max(t))
sm = mpl.cm.ScalarMappable(cNorm, cmap="brg")
cbb = plt.colorbar(sm,ax=ax1)
set1 = ax1.contourf(t, extent=(ymin,ymax,xmin,xmax), cmap="brg")
plt.show()
print("left .boundaries: {:s}".format(str(cba.boundaries)))
print("left ._boundaries: {:s}".format(str(cba._boundaries)))
print("right .boundaries: {:s}".format(str(cbb.boundaries)))
print("right len(._boundaries): {:s}".format(str(len(cbb._boundaries))))
For the left plot the colorbar has 9 boundaries and 8 discrete color values for the right one there are 257 boundaries.
I did a couple of vars(...) and dir(...) on the various objects. Where is decision made on the amount of boundaries and values made?
What is the deviation of the right plots colorbar creation from the default behaviour?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论