# Meshgrid

A Meshgrid is an ND-coordinate space generated by a set of arrays. Each point on the meshgrid corresponds to a combination of one value from each of the arrays.

#### New to Plotly?¶

Plotly's Python library is free and open source! Get started by downloading the client and reading the primer.

You can set up Plotly to work in online or offline mode, or in jupyter notebooks.

We also have a quick-reference cheatsheet (new!) to help you get started!

```
import plotly.plotly as py
import plotly.graph_objs as go
import numpy as np
```

#### Linspace/Arange to Meshgrid¶

The `np.meshgrid()`

function can be used to produce N-D coordinate grids. Let's construct an example to fully understand this.

If you give `np.meshgrid()`

two 1D arrays Array $A$ and Array $B$ such that $A$ is

and $B$ is

$$ \begin{align*} [b_1, b_2, b_3] \end{align*} $$then running `np.meshgrid(A, B)`

returns a list of two 2D arrays, which look like

and

$$ \begin{align*} [[b_1, b_1, b_1], [b_2, b_2, b_2], [b_3, b_3, b_3]] \end{align*} $$for which each array here contains arrays with an array full of the first item, the next filled with all the next item in the original array, etc.

By adding these two arrays together, we can create the 2D array containing, as its elements, every combination of sums between the numbers in the original elements. Arrays such as `linspace`

and `arange`

are typically used to constuct N-D arrays used to plot in 3 dimensions.

```
import plotly.plotly as py
import plotly.graph_objs as go
x = np.arange(-10, 10, 0.4)
y = np.arange(-10, 10, 0.4)
XX, YY = np.meshgrid(x, y)
ZZ = np.sin(XX**2 + YY**2) / (XX**2 + YY**2)
lines = []
line_marker = dict(color='#0066FF', width=2)
for i, j, k in zip(XX, YY, ZZ):
lines.append(go.Scatter3d(x=i, y=j, z=k, mode='lines', line=line_marker))
layout = go.Layout(
title='Wireframe with Meshgrid',
showlegend=False
)
fig = go.Figure(data=lines, layout=layout)
py.iplot(fig, filename='numpy-arange-to-meshgrid')
```

```
help(np.meshgrid)
```