'Plotting 2D data in matplotlib without imshow
I want to plot some 2D data on a colormap, with pixels uniformly distributed over the coordinates X, Y (as would result from e.g. np.meshgrid). Is there a way to do this in matplotlib without imshow()?
Consider two 2D data fields Z and W, which have values defined for the coordinates X, Y. Let's say I want to plot W as a simple colormap with nearest-value interpolation, and to over-plot Z as a set of contours. I would expect there to be two functions to do this with very similar calling signatures, e.g.
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111)
ax.interp2d(X, Y, W) # plots W with interpolation
ax.contour(X, Y, Z) # plots Z contours
I am wondering if a function like the placeholder interp2d exists.
imshow cannot accept X and Y, and instead requires configuring extent, origin, etc. in way that I find cumbersome an unintuitive, and is less readable.
I don't mind if the function is from a library other than matplotlib, as long asit can interface with matplotlib's axis objects.
Solution 1:[1]
The answer is plt.pcolor. I am overjoyed and will never use imshow again. This works just as I suggested in the question:
ax.imshow(X, Y, W)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | pretzlstyle |
