*21 Sep 2014* - This is a post on my blog.

For a long time I've wanted to do some code generated art. In the past I've messed around with D3 and matplotlib to generate some cool loking graphics, but never looked too deeply into what was possible. I recently stumbled onto this demo of making overlapping plots in matplotlib, and it re-sparked my curiosity about code generated art.

In this post I will show you some very basic techniques and ideas to make some pretty(?), randomly generated art (i.e. plots).

Scatter plotting is an easy way to generate artistic plots, as you can relatively easily control the parameters of every marker on your plot. We'll start with a very basic scatter plot of randomly located points.

In [62]:

```
# Take care of some environmental stuff
%pylab inline
import matplotlib.pyplot as plt
import numpy as np
figsize(10,10)
```

Populating the interactive namespace from numpy and matplotlib

In [63]:

```
bubs = 100
x = np.random.rand(bubs)
y = np.random.rand(bubs)
plt.scatter(x,y)
```

Out[63]:

<matplotlib.collections.PathCollection at 0x7ff994f90cd0>

In [64]:

```
bubs = 100
x = np.random.rand(bubs)
y = np.random.rand(bubs)
colors = plt.cm.jet(np.random.rand(bubs))
plt.scatter(x,y,color=colors)
```

Out[64]:

<matplotlib.collections.PathCollection at 0x7ff9a898d450>

Next we randomly vary the marker sizes.

In [65]:

```
bubs = 100
x = np.random.rand(bubs)
y = np.random.rand(bubs)
colors = plt.cm.jet(np.random.rand(bubs))
sizes = 2*np.pi*(20*np.random.rand(bubs))**2 # Area of markers
plt.scatter(x,y,color=colors,s=sizes)
```

Out[65]:

<matplotlib.collections.PathCollection at 0x7ff995352b90>

In [66]:

```
bubs = 100
x = np.random.rand(bubs)
y = np.random.rand(bubs)
colors = plt.cm.jet(np.random.rand(bubs))
sizes = 2*np.pi*(20*np.random.rand(bubs))**2 # Area of markers
plt.scatter(x,y, color=colors, s=sizes, alpha=0.4, lw=0)
```

Out[66]:

<matplotlib.collections.PathCollection at 0x7ff9a8957e10>

Next I wanted to try generating markers along some trajectory. A simple possibility was to plot markers along a sine curve. In this the position, size, and color are all related to the curve parameters.

Below are a few variations, changing the color generating value and the color map.

In [78]:

```
bubs = 100
cm = plt.cm.terrain
x = 2*np.pi*np.arange(bubs)/float(bubs)
y = 100*sin(x)
colors = cm(x/x.max())
sizes = np.pi*(8*(x+1))**2
plt.scatter(x, y, color=colors, s=sizes , alpha=0.4, edgecolor='w',lw=3)
```

Out[78]:

<matplotlib.collections.PathCollection at 0x7ff9aa8c7dd0>

In [79]:

```
bubs = 100
cm = plt.cm.terrain
x = 2*np.pi*np.arange(bubs)/float(bubs)
y = 100*sin(x)
colors = cm(np.random.rand(bubs))
sizes = np.pi*(8*(x+1))**2
plt.scatter(x, y, color=colors, s=sizes , alpha=0.4, edgecolor='w',lw=3)
```

Out[79]:

<matplotlib.collections.PathCollection at 0x7ff9aa8fe550>