Example #1
0
def plot_simple_heatmap_df():
    """
    Very basic example shows how heatmap_df takes a dataframe and returns
    an overview heatmap of the data with the help of pandas.qcut

    Returns:
        plotly plot in "offline" mode poped in the default browser.
    """
    a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
    b = [2, 4, 6, 8, 10, 2, 4, 6, 8, 10]
    c = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
    df = pd.DataFrame(data=np.asarray([a, b, c]).T,
                      columns=['var a', 'var b', 'var c'])
    pf = PlotlyFig(colorscale='Oregon')
    pf.heatmap_df(df, x_labels=['low','high'], y_labels=['q1','q2','q3','q4'])
Example #2
0
def plot_boston_dataset_heatmap_df():
    """
    This example uses sklearn boston dataset to plot a heatmap based on the
    binned data to see if there is a relationship between the Median house
    value w/ air NOX concentration and CHAS (Charles River dummy variable)

    Returns:
        plotly plot in "offline" mode poped in the default browser.
    """
    boston = datasets.load_boston()
    df_boston = pd.DataFrame(boston['data'], columns=boston['feature_names'])
    df_boston['Median value'] = boston.target

    pf = PlotlyFig(fontscale=0.8, filename='boston', colorscale='RdBu')
    pf.heatmap_df(df_boston[['NOX', 'CHAS', 'Median value']],
                  x_nqs=4,
                  y_labels=['otherwise', 'tract bounds river'])
Example #3
0
def plot_simple_heatmap_df():
    """
    Very basic example shows how heatmap_df takes a dataframe and returns
    an overview heatmap of the data with the help of pandas.qcut

    Returns:
        plotly plot in "offline" mode poped in the default browser.
    """
    a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
    b = [2, 4, 6, 8, 10, 2, 4, 6, 8, 10]
    c = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
    df = pd.DataFrame(data=np.asarray([a, b, c]).T,
                      columns=['var a', 'var b', 'var c'])
    pf = PlotlyFig(colorscale='Oregon')
    pf.heatmap_df(df,
                  x_labels=['low', 'high'],
                  y_labels=['q1', 'q2', 'q3', 'q4'])
Example #4
0
def plot_mean_elastic_tensors():
    """
    An example of heatmap_df where the input data is real and in dataframe
    format. We want to look at how average of the elastic constant tensor
    changes with the density and crystal system. Note that density is not
    a categorical variable in the final dataframe.

    Returns:
        plotly plot in "offline" mode poped in the default browser.
    """
    df = load_elastic_tensor()
    # data preparation:
    df['Mean Elastic Constant'] = df['elastic_tensor'].apply(lambda x: np.mean(x))
    gs = GlobalSymmetryFeatures(desired_features=['crystal_system'])
    df = gs.featurize_dataframe(df, col_id='structure')
    dsf = DensityFeatures(desired_features=['density'])
    df = dsf.featurize_dataframe(df, col_id='structure')
    # actual plotting
    pf = PlotlyFig(fontscale=0.75, filename='static_elastic_constants', colorscale='RdBu')
    pf.heatmap_df(df[['crystal_system', 'density', 'Mean Elastic Constant']])
Example #5
0
def plot_mean_elastic_tensors():
    """
    An example of heatmap_df where the input data is real and in dataframe
    format. We want to look at how average of the elastic constant tensor
    changes with the density and crystal system. Note that density is not
    a categorical variable in the final dataframe.

    Returns:
        plotly plot in "offline" mode poped in the default browser.
    """
    df = load_dataset("elastic_tensor_2015")
    # data preparation:
    df['Mean Elastic Constant'] = df['elastic_tensor'].apply(
        lambda x: np.mean(x))
    gs = GlobalSymmetryFeatures(desired_features=['crystal_system'])
    df = gs.featurize_dataframe(df, col_id='structure')
    dsf = DensityFeatures(desired_features=['density'])
    df = dsf.featurize_dataframe(df, col_id='structure')
    # actual plotting
    pf = PlotlyFig(fontscale=0.75,
                   filename='static_elastic_constants',
                   colorscale='RdBu')
    pf.heatmap_df(df[['crystal_system', 'density', 'Mean Elastic Constant']])