Quantcast
Viewing all articles
Browse latest Browse all 447

How can I get rid of diagonal tilting of shifting plt.pcolormesh() when shifting row positions?

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 npimport matplotlib.pyplot as pltxs = [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.


Viewing all articles
Browse latest Browse all 447

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>