This notebook is part of sequana, which was originally part of biokit
scatter plot with histogram: scatter_hist
%pylab inline
from sequana.viz import ScatterHist
import pandas as pd
Populating the interactive namespace from numpy and matplotlib
# input can be a 2-column matrix or a dataframe with 2 columns
X = pylab.randn(1000)
Y = pylab.randn(1000)
df = pd.DataFrame({'X':X, 'Y':Y})
sh = ScatterHist(df)
sh.plot()
(<matplotlib.axes._axes.Axes at 0x7f0379caaf98>, <matplotlib.axes._axes.Axes at 0x7f033fa99828>, <matplotlib.axes._axes.Axes at 0x7f033fa54e10>)
# 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})
# 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.iloc[:,0], df.iloc[:,1])]
df['size'] = [int(x**2*10+y**2*10) for x,y in zip(df.iloc[:,0], df.iloc[:,1])]
# 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')