我有 3 个数据集,X、Y、Z,它们分别是我的轴和我的数据。它们定义明确,即 len(X) = len(Y) = len(Z) = len(Z[i]) = N for i in range(0,N).
我想制作一个类似于 contourf 图(我已经制作了),但是使用离散轴,就像“等高线方 block ”一样,其中每个方 block (x,y) 都有一个Z 值(浮点值)给出的颜色。
到目前为止,我使用的是 contourf(X,Y,Z),但它进行了一些我不想要的插值,我需要使用正方形进行更好的可视化。
有人知道怎么做吗?
谢谢
最佳答案
您应该使用 matshow 或 imshow 绘图函数。
这里的一个重要参数是插值。 检查这个example from the matplotlib gallery查看一些示例。
通过使用 matshow(),关键字参数被传递给 imshow()。 matshow() 为origin、interpolation(='nearest')和aspect<设置默认值/em>.
这是我自己工作中的一个例子...
# level, time and conc are previously read from a file
X,Y=[level,time]
Z=conc.transpose() # Create the data to be plotted
cax = matshow(Z, origin='lower', vmin=0, vmax=500)
# I am telling all the Z values above 500 will have the same color
# in the plot (if vmin or vmax are not given, they are taken from
# the input’s minimum and maximum value respectively)
grid(True)
cbar = colorbar(cax)
...返回此图:
关于python - 方点等高线图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9579217/