pydata/pandas — pull request #8885 by onesandzeroes (2014-11-24 10:47:40+00:00)
Title: ENH/VIS: Pass DataFrame column to `size` argument in `df.scatter`

Originally discussed in #8244. Currently this only uses the column from the dataframe if the `s` argument is a string, supporting int column names is ambiguous and liable to break existing code, but if people can think of a good way to do this I'll try to add it.

Example output:

```python
import pandas as pd
import numpy as np
import random

df = pd.DataFrame({
'x': np.linspace(0, 50, 6),
'y': np.linspace(0, 20, 6),
'cat_column': random.sample('abcdabcdabcd', 6)
})
df['cat_column'] = pd.Categorical(df['cat_column'])

# Numeric column: linear scaling of point sizes
df.plot(kind='scatter', x='x', y='y', s='x')
```

![image](https://cloud.githubusercontent.com/assets/1460294/5163679/70a09820-7422-11e4-8bf3-7a15fb072f71.png)

```python
# Categorical columns: fixed set of sizes
df.plot(kind='scatter', x='x', y='y', s='cat_column')
```

![image](https://cloud.githubusercontent.com/assets/1460294/5163691/91671f16-7422-11e4-92fd-18b7f67b5b41.png)

The minimum and maximum point sizes we scale have a default range of `(50, 1000)`, and
can be adjusted with the ``size_range`` arg:

```python
# Smaller range of sizes than default
df.plot(kind='scatter', x='x', y='y', s='x',
size_range=(200, 800))
```

![image](https://cloud.githubusercontent.com/assets/1460294/5163729/04e4f44a-7423-11e4-9e85-902d9dd1caaa.png)

Picking good defaults for the range of sizes is pretty hard as these sizes are absolute- matplotlib
sets the size in terms of points. The ability to tweak up and down with the `size_range` arg is
probably going to be needed, but open to suggestions on good defaults.
.