D1X - 1 year ago 61

Python Question

I am (numerically) solving the Lorenz System by using different methods. I am plotting it using matplotlib but I would like a way to distinguish better the points.

For example:

Let's assume the points to be plotted are stored in the array

`a`

`array([[ 0.5 , 0.5 , 0.5 ],`

[ 0.50640425, 0.6324552 , 0.48965064]])

#...

Now these lines of code

`import matplotlib.pyplot as plt`

from mpl_toolkits.mplot3d import Axes3D

fig = plt.figure()

ax = fig.add_subplot(111, projection='3d')

ax.plot(a[:,0],a[:,1],a[:,2])

plt.show()

produce:

Not very descriptive, is it? So I thought plotting discrete points would work better. So these ones:

`import matplotlib.pyplot as plt`

from matplotlib import cm

from mpl_toolkits.mplot3d import Axes3D

fig = plt.figure()

ax = fig.add_subplot(111, projection='3d')

ax.scatter(a[:,0],a[:,1],a[:,2], s=0.2)

plt.show()

produce:

But it is not as descriptive as I want. I want to know what is the most descriptive way to plot the Lorenz system.

Answer Source

Consider making your scatter points transparent. You can do this by passing an `alpha`

keyword to `plt.scatter`

. Here's an example, modified from `mplot3d`

example gallery, with `alpha = 1.0`

, which is the default value:

```
ax.scatter(xs, ys, zs, alpha=1.0, s=0.2)
```

And here is the same scatter point cloud drawn with `alpha = 0.1`

:

```
ax.scatter(xs, ys, zs, alpha=0.1, s=0.2)
```

Note that while this appears to be a good visualization, the interactive part of it is quite slow for a large number of points. If you really need fast performance, consider an alternative approach - splitting the lines in segments and coloring them by index, similarly to what's being done here.