mirror of
https://github.com/davrot/pytutorial.git
synced 2025-04-15 11:56:34 +02:00
Update README.md
Signed-off-by: David Rotermund <54365609+davrot@users.noreply.github.com>
This commit is contained in:
parent
5f70df3bc6
commit
981a026a9a
1 changed files with 40 additions and 0 deletions
|
@ -47,3 +47,43 @@ plt.show()
|
|||

|
||||
|
||||

|
||||
|
||||
An example:
|
||||
|
||||
```python
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
x = np.linspace(0, 1, 100)
|
||||
y = np.linspace(0, 1, 100)
|
||||
|
||||
xv, yv = np.meshgrid(x, y)
|
||||
|
||||
a = np.sin(xv * 2 * np.pi) * np.sin(yv * 8 * np.pi)
|
||||
|
||||
plt.imshow(a, cmap="hot")
|
||||
plt.xlabel("x axis")
|
||||
plt.ylabel("y axis")
|
||||
plt.show()
|
||||
```
|
||||
|
||||

|
||||
|
||||
**The question is if you really need a mesh or if just using broadcasting can do the job too.** I guess this depends on your need.
|
||||
|
||||
```python
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
x = np.linspace(0, 1, 100)[np.newaxis, :]
|
||||
y = np.linspace(0, 1, 100)[:, np.newaxis]
|
||||
|
||||
a = np.sin(x * 2 * np.pi) * np.sin(y * 8 * np.pi)
|
||||
|
||||
plt.imshow(a, cmap="hot")
|
||||
plt.xlabel("x axis")
|
||||
plt.ylabel("y axis")
|
||||
plt.show()
|
||||
```
|
||||
|
||||

|
||||
|
|
Loading…
Add table
Reference in a new issue