ScatterMatrix Reference Implementation

In [1]:
%matplotlib inline
In [2]:
import matplotlib as mpl; mpl.rcParams['savefig.dpi'] = 144
import matplotlib.pyplot as plt
import io_helpers as ioh
import loadable_helpers as lh
import constants as C

Style

In [3]:
# Font Family
mpl.rcParams['font.family'] = 'serif'

# Lines
mpl.rcParams['lines.linewidth'] = 1.0

# Adjust ticks
mpl.rcParams['xtick.major.size'] = 4
mpl.rcParams['xtick.minor.size'] = 2
mpl.rcParams['ytick.major.size'] = 4
mpl.rcParams['ytick.minor.size'] = 2

# Adjust Font Size
mpl.rcParams['xtick.labelsize']  = 'x-small'
mpl.rcParams['ytick.labelsize']  = 'x-small'
mpl.rcParams['axes.labelsize']   = 'small'
mpl.rcParams['axes.titlesize']   = 'small'
mpl.rcParams['axes.titlesize']   = 'x-small'

Load Data

In [4]:
basedir, sims, nruns = lh.chaos_sims()
nstep_max = 9e9
In [5]:
df_all = []
for isim, csim in enumerate(sims):
    print "// %s" % csim
    fnames = []
    for nrun in nruns[isim]:
        fnames.append("%s/%s/run_%02d/Out_run_%02d_%012d.dat" % (basedir, csim, nrun, nrun, nstep_max))
    df = ioh.read_output_and_stack(fnames, frame='heliocentric')
    df = df[df.mass < 12.0]
    df_all.append(df)
// Chaos-VAN/gas_01
// Chaos-VAN_Steep/gas_01
// Chaos-VAN_Heavy/gas_01
// Chaos-EJS/gas_01
// Chaos-EJS_Steep/gas_01
// Chaos-EJS_Heavy/gas_01
// Chaos-CJS/gas_01

Scatter Matrix Code

In [6]:
def scatter_matrix(data_array, data_tags, data_array_lo, data_array_hi, data_array_ticks):
    """
    Plot Scatter Matrix.
    """
    
    N = len(data_array)
    fig, axarr = plt.subplots(N-1,N-1)
    #fig.set_size_inches(8.27,8.27*(6./8.)*2./3.)
    fig.set_size_inches(8.27,8.27*(6./8.))
    
    # Remove Lower Left Half
    for irow in range(N-1):
        for icol in range(irow):
            ax = axarr[irow,icol]
            #ax.scatter(0,0,c='b')
            #plt.setp(ax.get_xticklabels(), visible=False)
            fig.delaxes(ax)
            
    # Plot Data
    for irow in range(N-1):
        for icol in range(irow,N-1):
            # Extract Axis
            ax = axarr[irow,icol]
            
            # Debug
            # ax.scatter(1,1,c='r')
            
            # Extract Data
            xdata = data_array[icol+1]
            ydata = data_array[irow]
            
            # Extract Axis Labels
            xlabel = data_tags[icol+1]
            ylabel = data_tags[irow]
            
            # Extract Data Limits
            xlo = data_array_lo[icol+1]
            xhi = data_array_hi[icol+1]
            ylo = data_array_lo[irow]
            yhi = data_array_hi[irow]
            
            # Extract Ticks
            xticks = data_array_ticks[icol+1]
            yticks = data_array_ticks[irow]
            
            # Plot Data
            ax.scatter(xdata, ydata, s=2**2, c='k', edgecolor='none')
            
            # Plot Axis Label
            if icol == irow:
                ax.set_ylabel(ylabel)
                ax.set_xlabel(xlabel)
            # Remove Tick Marks
            else:
                plt.setp(ax.get_xticklabels(), visible=False)
                plt.setp(ax.get_yticklabels(), visible=False)
                
            # Set Axis Limits
            ax.set_xlim([xlo, xhi])
            ax.set_ylim([ylo, yhi])
            
            # Set Axis Ticks
            ax.set_xticks(xticks)
            ax.set_yticks(yticks)
        
    # Tighten
    fig.subplots_adjust(hspace=0, wspace=0)

Generate Plot

In [7]:
df = df_all[6]
data_array = [ df.mass, df.e, df.i*C.r2d, df.a ]
data_array_lo = [ 0.0, 0.0, 0.0, 0.0 ]
data_array_hi = [ 2.0, 1.0, 90.0, 6.0 ]
data_array_ticks = [ [ 0.5, 1.0, 1.5], \
                     [ 0.2, 0.4, 0.6, 0.8 ], \
                     [ 15, 30, 45, 60, 75 ], \
                     [ 1, 2, 3, 4, 5 ] ]
data_tags = [ "Mass (Earth Masses)", "Eccentricity", "Inclination (Degree)", "Semi-Major Axis (AU)" ]
scatter_matrix(data_array, data_tags, data_array_lo, data_array_hi, data_array_ticks)