<jupyter_start><jupyter_text>Interactive fracture analysis<jupyter_code>import pandas as pd
%matplotlib inline
import matplotlib.pyplot as plt
import seaborn as sns
from ipywidgets import interact
import ipywidgets as widgets
import mplstereonet as mpl
from mpl_toolkits.axes_grid1.inset_locator import inset_axes<jupyter_output><empty_output><jupyter_text>Import fracture data using Pandas<jupyter_code>df = pd.read_csv('../data/image_data.csv', index_col='Unnamed: 0')
df.head()
df.shape
df.describe()<jupyter_output><empty_output><jupyter_text>Inspect fracture data with matplotlib/seaborn<jupyter_code>df.columns
sns.pairplot(data=df, 
             vars=['DIP', 'AZIM'],
             hue='DIPTYPE',
             palette='colorblind',
             markers=['x','o','v','^','s','p'],
             height=3
            )
plt.show()<jupyter_output><empty_output><jupyter_text>Inspect fracture data with interactive mplstereonet<jupyter_code>@interact(diptype=['FRACTURE', 'HEALEDFRACTURE', 'DRILL.IND.FRAC.', 'BREAKOUT', 'BED', 'BED_LOW_CONF'],
          alpha=widgets.FloatSlider(min=0, max=1, step=0.05, continuous_update=False), 
          poles=False,
          show_mean=False,
          density=False,
         )
def plot_data(diptype, alpha, poles, show_mean, density):
    """
    plot a stereonet of image data
    args:
        diptype, alpha, poles, show_mean, density
    returns:
        None
    """
    # set up the plot
    fig, ax = mpl.subplots(figsize=(6,6), ncols=1, nrows=1)

    # get data
    strike, dip = df.AZIM.loc[df['DIPTYPE'] == diptype], df.DIP.loc[df['DIPTYPE'] == diptype]
    
    # great circles
    ax.plane(strike, dip, 'g-', linewidth=1, alpha=alpha)
    
    # plot decoration
    ax.grid(color='k', alpha=0.2)
    data_count = strike.count()
    mean_azim = strike.mean()
    mean_dip = dip.mean()
    ax.text(0, 10, f'N points: {data_count}\nmean Azim: {mean_azim:.1f}\nmean Dip: {mean_dip:.1f}')
    
    # options
    if poles:
        ax.pole(strike, dip, 'kx', markersize=3, alpha=1)
    
    if show_mean:
        ax.plane(mean_azim, mean_dip, 'r--', lw=3, alpha=0.7)
        ax.pole(mean_azim, mean_dip, 'rs', markersize=5, alpha=0.7)

    if density:
        im = ax.density_contourf(strike, dip, measurement='poles', alpha=0.3)
        axins = inset_axes(ax,
                   width="5%",
                   height="45%",
                   loc='lower left',
                   bbox_to_anchor=(1.05, 0., 1, 1),
                   bbox_transform=ax.transAxes,
                   borderpad=0,
                   )
        cbar = fig.colorbar(im, cax=axins)
        cbar.ax.get_yaxis().labelpad = 15
        cbar.ax.set_ylabel('Orientation density distribution', rotation=90)

    return None<jupyter_output><empty_output>