I am trying to create a contour plot with the x coordinates being label EF and y being labeled EB and z being a function labeled a. It returns a long error posted below. Any help would be appreciated. The error is
File "contour.py", line 19, in <module>
c = plt.contour(EF,EB,a)
File "/usr/lib/pymodules/python2.7/matplotlib/pyplot.py", line 2016, in contour
ret = ax.contour(*args, **kwargs)
File "/usr/lib/pymodules/python2.7/matplotlib/axes.py", line 7326, in contour
return mcontour.QuadContourSet(self, *args, **kwargs)
File "/usr/lib/pymodules/python2.7/matplotlib/contour.py", line 1088, in __init__
ContourSet.__init__(self, ax, *args, **kwargs)
File "/usr/lib/pymodules/python2.7/matplotlib/contour.py", line 686, in __init__
self._process_args(*args, **kwargs)
File "/usr/lib/pymodules/python2.7/matplotlib/contour.py", line 1101, in _process_args
x, y, z = self._contour_args(args, kwargs)
File "/usr/lib/pymodules/python2.7/matplotlib/contour.py", line 1148, in _contour_args
x,y,z = self._check_xyz(args[:3], kwargs)
File "/usr/lib/pymodules/python2.7/matplotlib/contour.py", line 1180, in _check_xyz
raise TypeError("Input z must be a 2D array.")
TypeError: Input z must be a 2D array.
The error states that
TypeError: Input z must be a 2D array.
if you look at the sizes of the input objects:
print EF.shape, EB.shape, a.shape
(51,) (51,) (51,)
you'll see that these are not 2D arrays. Did you intend to use X and Y instead?
When I make the change to
a = ((1+.5*(np.exp(1.7*X)+np.exp(1.7*Y)+np.exp(1.7*(X+Y))))/(1+np.exp(1.7*X)+np.exp(1.7*Y)+np.exp(1.7*(X+Y))))
c = plt.contour(EF,EB,a,30)
The output is

It looks like you may need to adjust your parameter space since all the interesting stuff is around (0,0).
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