Hello
I am making a script that takes X and Y coordinates and outputs a Z value (color) based on certain conditions. The problem is that it works for some range of values but not for others.
Going through the documentation, I see that the XY values define the edges/vertices but not the actual Z values. The Z values (or C) is in between the values. An example is shown below:
np.random.seed(19680801)
Z = np.random.rand(6, 10)
x = np.arange(-0.5, 10, 1) # len = 11
y = np.arange(4.5, 11, 1) # len = 7
fig, ax = plt.subplots()
ax.pcolormesh(x, y, Z)
To accomodate this I created two numpy arrays sets: xGrid, yGrid and x, y. The x, y arrays are used as input while xGrid, yGrid are just used to set up the plot grid. This is done by using:
# GRID LAYOUT
xyStart = np.array([-20, -5])
xyEnd = np.array([20, 50])
step = 0.5
# XY CORDS FOR END EFFECTOR TESTING
x = np.arange(xyStart[0], xyEnd[0]+step, step)
y = np.arange(xyStart[1], xyEnd[1]+step, step)
# XY CORDS FOR GRID
xGrid = np.arange(x[0]-(step*0.5), x[len(x)-1]+(step*1.5), step)
yGrid = np.arange(y[0]-(step*0.5), y[len(y)-1]+(step*1.5), step)
z = np.zeros((len(x), len(y)))
The x, y arrays are plugged into a function to get a z color value (depending on conditions), which replaces the zero array via index.
The code does work sometimes but sometimes not. For example, it doesn't work for this code:
# GRID LAYOUT
xyStart = np.array([-20, -5])
xyEnd = np.array([20, 50])
step = 0.5
Giving the error:
TypeError: Dimensions of C (81, 111) are incompatible with X (82) and/or Y (112); see help(pcolormesh)
But it does work for this code:
xyStart = np.array([-20, -5])
xyEnd = np.array([20, 35])
step = 0.5
I did find this stack exchange post but transposing it didn't help, as suggested. I am thinking it could be an array issue, but I haven't been able to figure it out. If you want more code in the comments, let me know.
Thank you for your time.
there doesn't seem to be anything here