scatter demonstration


In [1]:
%pylab inline
from biokit import ScatterHist
import pandas as pd


Populating the interactive namespace from numpy and matplotlib

Scatter plot with histogram


In [2]:
# input can be a 2-column matrix or a dataframe with 2 columns
X = pylab.randn(1000)
Y = pylab.randn(1000)

In [3]:
df = pd.DataFrame({'X':X, 'Y':Y})

In [4]:
sh = ScatterHist(df)
sh.plot()


/home/cokelaer/miniconda3/envs/py3/lib/python3.5/site-packages/matplotlib/cbook.py:136: MatplotlibDeprecationWarning: The axisbg attribute was deprecated in version 2.0. Use facecolor instead.
  warnings.warn(message, mplDeprecation, stacklevel=1)
Out[4]:
(<matplotlib.axes._axes.Axes at 0x7fd9d3a09e10>,
 <matplotlib.axes._axes.Axes at 0x7fd9d398c240>,
 <matplotlib.axes._axes.Axes at 0x7fd9d3970710>)

In [5]:
# you can tune the scatter plot and histogram with valid optional 
# arguments expected by the pylab functions. Check the pylab.hist 
# and pylab.scatter helps for details.
_ = sh.plot(kargs_scatter={'c':'r', 's':30, 'alpha':.3},
                   kargs_histy={'color':'g', 'bins':20})


/home/cokelaer/miniconda3/envs/py3/lib/python3.5/site-packages/matplotlib/cbook.py:136: MatplotlibDeprecationWarning: The axisbg attribute was deprecated in version 2.0. Use facecolor instead.
  warnings.warn(message, mplDeprecation, stacklevel=1)

In [6]:
# you can fix the size and color of the markers in the scatter plot as
# shown above with the 'c' and 's' parameters.
# However, if you use a dataframe, you can populate it with a 'size'
# and 'color' columsn, which will be interpreted automatically.
df['color'] = [abs(int(1-(x**2+y**2)))/10. for x,y in zip(df.ix[:,0], df.ix[:,1])]
df['size'] = [int(x**2*10+y**2*10) for x,y in zip(df.ix[:,0], df.ix[:,1])]


/home/cokelaer/miniconda3/envs/py3/lib/python3.5/site-packages/ipykernel_launcher.py:5: DeprecationWarning: 
.ix is deprecated. Please use
.loc for label based indexing or
.iloc for positional indexing

See the documentation here:
http://pandas.pydata.org/pandas-docs/stable/indexing.html#ix-indexer-is-deprecated
  """

In [7]:
# you can also tune the position and size of the different axes 
# in the figure 
# W fixes the width of scatter (and therefore top hist)
# hist_position='left' moves the right histo to the left
dummy = sh.plot(kargs_scatter={'c':df['color'], 's': df['size']},
                   kargs_histy={'color':'g'}, 
                   axisbg='lightgrey',
                   width=.6,
                   hist_position='left')


/home/cokelaer/miniconda3/envs/py3/lib/python3.5/site-packages/matplotlib/cbook.py:136: MatplotlibDeprecationWarning: The axisbg attribute was deprecated in version 2.0. Use facecolor instead.
  warnings.warn(message, mplDeprecation, stacklevel=1)