I want to make a contour plot of some data, but it is possible that all the values in the field are at the same value. This causes an error in matplotlib, which makes sense since there really is no outline. For example, if you run the code below, you will receive an error message, but delete the second definition ziand it will work as expected.
How can I make a “contour” graph for some data if it is a uniform field? I want it to look just like a regular contour plot (to have a box filled with some kind of color and show the color bar on the side. The color bar can be a uniform color or still show a range of 15 colors, not caring).
the code:
from numpy import array
import matplotlib.pyplot as plt
xi = array([0., 0.5, 1.0])
yi = array([0., 0.5, 1.0])
zi = array([[0., 1.0, 2.0],
[0., 1.0, 2.0],
[0., 1.0, 2.0]])
zi = array([[1.0, 1.0, 1.0],
[1.0, 1.0, 1.0],
[1.0, 1.0, 1.0]])
CS = plt.contour(xi, yi, zi, 15, linewidths=0.5, colors='k')
CS = plt.contourf(xi, yi, zi, 15, cmap=plt.cm.jet)
plt.colorbar()
plt.show()