Jasper C. - 2 months ago 10x

Python Question

I asked a related question yesterday and fortunately got my answer from jlarsch quickly. But now I am stuck with the next part, which starts with the h=area() line. I'd like to know the python version of the area() function, via which I will be able to set the colors. Could someone shed me some light again? Thanks much in advance.

...

Subplot (2,1,1);

H = plot (rand(100,5));

C = get (H, 'Color')

H = area (myX, myY);

H(1).FaceColor = C(1);

H(2).FaceColor = C(2);

Grid on;

...

Answer

The pretty much exact equivalent of MATLAB's Area plot is matplotlib's stackplot. Here is the first MATLAB example from the above link reproduced using matplotlib:

```
import matplotlib.pyplot as plt
import numpy as np
x = np.arange(4)
y = [[1, 3, 1, 2],
[5, 2, 5, 6],
[3, 7, 3, 1]]
plt.stackplot(x, y)
plt.show()
```

And here is the result:

Source (Stackoverflow)

Comments