pyplot 在哪里定义级别数

发布于 2025-01-09 00:35:40 字数 1412 浏览 1 评论 0原文

我试图了解如何在轮廓工具链中创建级别、值、边界。

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文