admin管理员组文章数量:1123035
I am plotting a 2D heat map as part of my research in python using plt.colormesh() and I am able to get nice plots this way: raw data plot
I want to get rid of the bowing (artifact of experimental set up) by shifting each row to make that hot curve a vertical hot line.
I have written code to locate and shift each x row in the Xmesh to align the hot line. When I plot the data with this shifted Xmesh, the centers of each 'pixel' are aligned nicely, but each 'pixel' effectively gets tilted: data plotted with shifted Xmesh
Is there a way to shift the rows and not have this tilting effect?
Below is a simple example code demonstrating this phenomena:
import numpy as np
import matplotlib.pyplot as plt
xs = [1,3,4,8]
ys = [5,6,7,8]
zGrid = np.random.rand(len(xs),len(ys))
X,Y = np.meshgrid(xs,ys)
print(X)
print(Y)
Xshifted = np.zeros([len(X),len(Y)])
shifts = [0,1,2,1]
for i in range(len(Y[0])):
for j in range(len(X[0])):
Xshifted[i,j] = X[i,j] - shifts[i]
fig, axs = plt.subplots(2,1)
axs[0].pcolormesh(X,Y,zGrid,shading='nearest',cmap=plt.cm.jet,)
axs[1].pcolormesh(Xshifted,Y,zGrid,shading='nearest',cmap=plt.cm.jet,)
plt.show()
which gives these two plots showing un-shifted (top) and shifted (bottom) plots:
simple case plots
I looked around in the documentation and found an "offsets" key word argument, but the documentation around it is nearly non-existent and I could not find any examples.
本文标签:
版权声明:本文标题:python - How can I get rid of diagonal tilting of shifting plt.pcolormesh() when shifting row positions? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736543484a1944416.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论