Pretag

# Contour plot, TypeError: Length of y must be number of rows in z

90%

Where X and Y are 2D arrays of the x and y points, and Z is a 2D array of points that determines the color of the areas on the 2D plot,,Where X and Y are 2D arrays of the x and y points, and Z is a 2D array of points that determines the "height" of the contour, which is represented by color in a 2D plot

Example_snippet/controller/utility/_number.js/ ax.contour(X, Y, Z)
. . .

ax.contour(X, Y, Z)

Step 2 continued with import numpy as np
import matp. . .

```
import numpy as np
import matplotlib.pyplot as plt
#
if using a Jupyter notebook, include:
%
matplotlib inline
x = np.arange(-3.0, 3.0, 0.1)
y = np.arange(-3.0, 3.0, 0.1)
X, Y = np.meshgrid(x, y)
Z = np.sin(X) * np.cos(Y)
fig, ax = plt.subplots(figsize = (6, 6))
ax.contour(X, Y, Z)
plt.show()
```

Step 3 continued with ax.contourf(X, Y, Z)
. . .

ax.contourf(X, Y, Z)

Step 4 continued with import numpy as np
import matp. . .

```
import numpy as np
import matplotlib.pyplot as plt
#
if using a Jupyter notebook, include:
%
matplotlib inline
x = np.arange(-3.0, 3.0, 0.1)
y = np.arange(-3.0, 3.0, 0.1)
X, Y = np.meshgrid(x, y)
Z = np.sin(X) * np.cos(Y)
fig, ax = plt.subplots(figsize = (6, 6))
ax.contourf(X, Y, Z)
plt.show()
```

Step 5 continued with cf = ax.contourf(X,Y,Z)
fig.co. . .

cf = ax.contourf(X, Y, Z) fig.colorbar(cf, ax = ax)

Step 6 continued with import numpy as np
import matp. . .

```
import numpy as np
import matplotlib.pyplot as plt
#
if using a Jupyter notebook, include:
%
matplotlib inline
x = np.arange(-3.0, 3.0, 0.1)
y = np.arange(-3.0, 3.0, 0.1)
X, Y = np.meshgrid(x, y)
Z = np.sin(X) * np.cos(Y)
fig, ax = plt.subplots(figsize = (6, 6))
ax.set_aspect('equal')
cf = ax.contourf(X, Y, Z)
fig.colorbar(cf, ax = ax)
plt.show()
```

Step 7 continued with mycmap = plt.get_cmap('gist_ea. . .

```
mycmap = plt.get_cmap('gist_earth')
ax.contourf(X, Y, Z, cmap = mycmap)
```

Step 8 continued with import matplotlib.pyplot as pl. . .

```
import matplotlib.pyplot as plt
import numpy as np
#
if using a Jupyter notebook, include:
%
matplotlib inline
x = np.arange(-3.0, 3.0, 0.1)
y = np.arange(-3.0, 3.0, 0.1)
X, Y = np.meshgrid(x, y)
Z = np.sin(X) * np.cos(Y)
fig, (ax1, ax2) = plt.subplots(1, 2, figsize = (12, 6))
mycmap1 = plt.get_cmap('gist_earth')
ax1.set_aspect('equal')
ax1.set_title('Colormap: gist_earth')
cf1 = ax1.contourf(X, Y, Z, cmap = mycmap1)
fig.colorbar(cf1, ax = ax1)
mycmap2 = plt.get_cmap('gnuplot2')
ax2.set_aspect('equal')
ax2.set_title('Colormap: gnuplot2')
cf2 = ax2.contourf(X, Y, Z, cmap = mycmap2)
fig.colorbar(cf2, ax = ax2)
plt.show()
```

88%

I have created a function with two arguments, func(x,y), I would now like to plot this as a 2D contour plot, first as func(x,y) vs

Example_snippet/controller/utility/_number.js/ import matplotlib
import matpl. . .

```
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.cm as cm
import matplotlib.mlab as mlab
matplotlib.rcParams['xtick.direction'] = 'out'
matplotlib.rcParams['ytick.direction'] = 'out'
x = np.logspace(5e4, 8e4, num = 20)
y = np.logspace(1e10, 1e12, num = 20)
z = np.asarray([func(x, y), x])
plt.figure()
CS = plt.contour(x, y, z)
plt.clabel(CS, inline = 1, fontsize = 10)
```

Step 2 continued with print x.shape
print y.shape
pr. . .

print x.shape print y.shape print z.shape

Step 3 continued with (20,)
(20,)
(2, 20)
. . .

(20, ) (20, ) (2, 20)

Step 4 continued with TypeError: Length of y must be. . .

`TypeError: Length of y must be number of rows in z.`

72%

From the docs for contour: "X and Y must both be 2-D with the same shape as Z, or they must both be 1-D such that len(X) is the number of columns in Z and len(Y) is the number of rows in Z," (This is the version for 1D X and Y

Example_snippet/controller/utility/_contour.js/ import pylab as pb
import . . .

```
import pylab as pb
import numpy as np
import matplotlib.pyplot as plt
def f(x, y):
return np.log(x ** 2 + y ** 2)
x = np.logspace(np.log10(5e4), np.log10(8e4), num = 20)
y = np.logspace(np.log10(5e4), np.log10(9e4), num = 20)
X, Y = np.meshgrid(x, y)
z = f(X, Y)
print x
print y
print min(z.flat), max(z.flat), min(x), max(x), min(y), max(y)
plt.figure()
CS = plt.contour(x, y, z)
plt.clabel(CS, inline = 1, fontsize = 10)
pb.show()
```

30%

#### Other "number-contour" answers related to "Contour plot, TypeError: Length of y must be number of rows in z"

- Python/Pandas - building a new column based in columns comparison
- Query a multi-level JSON object stored in MySQL
- Use make variable in builtin shell function in a Makefile
- Failing to open HTTPS pages in PhantomJS using Splinter
- How to sync a MySQL databases between two remote databases (without MySQL database replication technique )
- Django - Assigning Id to model
- Bashcov - does not work if subprogram is called by python
- Tkinter checkbutton - text won't show up
- Knight's Tour in Python - Getting Path from Predecessors
- Catching events within QtDesigner generated widget
- Initial weights in Network with Keras / Tensorflow
- Using data from one Django application in another
- Python: __qualname__ of function with decorator
- Creating a drop-down menu of Member IDs
- How to remove an item from a dictionary that is iterated?
- Return price as an object/variable using Interactive Brokers TWS API - Python
- For loop is not working while appending rows
- Python help to debug an error when modify a file in a stream mode
- Mido - How to get midi data in realtime from different ports
- Using Java's ByteBuffer to replicate Python's struct.pack