When I use pcolor involving meshes and data consisting of a single column, the resulting plot is just white everywhere. What am I doing wrong?
import matplotlib.pyplot as plt
from numpy import array
U = array([[0],[1]])
V = array([[0],[0]])
data = array([[0.4],[0.5]])
plt.pcolor(U,V,data)
plt.show()
This is part of a more general program where the arrays can have different sizes. Ideally, the solution should also generalize to arrays that also consist of multiple rows and columns.
Quoting from matplotlib documentation
The dimensions of X and Y should be one greater than those of C.
In your case, X=U, Y=V and C=data. But all your arrays have shape (2,1)
Note that this quote of the documentation is quite logical. Coordinates passed (U and V here) are coordinates of the corners of the boxes. Your data contains two boxes. There are 6 corners (4 outer corners, and 2 in common).
import numpy as np
import matplotlib.pyplot as plt
U=np.array([[0, 1], [0, 1], [0, 1]])
V=np.array([[0, 0], [1, 1], [2, 2]])
data=np.array([[0.4],[0.5]])
plt.pcolor(U,V,data)
plt.show()

Note that in this very case (x goes from 0 to 1, for 1 cell, and y goes from 0 to 2, for 2 cells), you would achieve the exact same result by just calling plt.pcolor(data), without specifying U and V.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With