示例#1
0
def advanced_histogram():
    """
    This is a work in progress
    """

    df = load_elastic_tensor()
    pf = PlotlyFig(df, title="Various Histograms")
    pf.histogram(cols=['G_Reuss', 'G_VRH', 'G_Voigt'], bins={'size': 10})
示例#2
0
def advanced_histogram():
    """
    This is a work in progress
    """

    df = load_elastic_tensor()
    pf = PlotlyFig(df, title="Various Histograms")
    pf.histogram(cols=['G_Reuss', 'G_VRH', 'G_Voigt'], bins={'size': 10})
 def test_elastic_tensor(self):
     df = load_elastic_tensor()
     self.assertEqual(type(df['structure'][0]), Structure)
     for c in [
             'compliance_tensor', 'elastic_tensor',
             'elastic_tensor_original'
     ]:
         self.assertEqual(type(df[c][0]), np.ndarray)
     self.assertEqual(len(df), 1181)
     column_headers = [
         'material_id', 'formula', 'nsites', 'space_group', 'volume',
         'structure', 'elastic_anisotropy', 'G_Reuss', 'G_VRH', 'G_Voigt',
         'K_Reuss', 'K_VRH', 'K_Voigt', 'poisson_ratio',
         'compliance_tensor', 'elastic_tensor', 'elastic_tensor_original'
     ]
     self.assertEqual(list(df), column_headers)
     df = load_elastic_tensor(include_metadata=True)
     column_headers += ['cif', 'kpoint_density', 'poscar']
     self.assertEqual(list(df), column_headers)
示例#4
0
 def test_elastic_tensor(self):
     df = load_elastic_tensor()
     self.assertEqual(len(df), 1181)
     column_headers = {
         'idx', 'G_Reuss', 'G_VRH', 'G_Voigt', 'K_Reuss', 'K_VRH',
         'K_Voigt', 'compliance_tensor', 'elastic_anisotropy',
         'elastic_tensor', 'elastic_tensor_original', 'formula',
         'kpoint_density', 'material_id', 'nsites', 'poisson_ratio',
         'poscar', 'space_group', 'structure', 'volume'
     }
     self.assertEqual(set(list(df)), column_headers)
示例#5
0
def plot_bulk_shear_moduli():
    """
    Very basic example of xy scatter plot of Voigt-Reuss-Hill (VRH) average
        bulk vs. shear modulus. Poisson ratio as marker colors make the
        distinction between materials with different bulk/shear modulus ratios
    Returns:
        plotly plot in "offline" mode popped in the default browser.
    """
    df = load_elastic_tensor()
    pf = PlotlyFig(df,
                   y_title='Bulk Modulus (GPa)',
                   x_title='Shear Modulus (GPa)',
                   filename='bulk_shear_moduli.jpeg')
    pf.xy(('G_VRH', 'K_VRH'), labels='material_id', colors='poisson_ratio',
          colorscale='Picnic', limits={'x': (0, 300)})
示例#6
0
def formatting_example(api_key, username):
    """
    Demonstrate common and advanced formatting features of PlotlyFig.

    PlotlyFig provides a set of arguments which make setting up good
    looking Plotly templates quick(er) and easy(er).

    Most formatting options can be set through the initializer of PlotlyFig.
    These options will remain the same for all figures producted, but you can
    change some common formatting options after instantitating a PlotlyFig
    object using set_arguments.

    Chart-specific formatting options can be passed to plotting methods.
    """

    if not api_key or not username:
        raise ValueError("Specify your Plotly api_key and username!")

    df = load_elastic_tensor()

    pf = PlotlyFig(df=df,
                   api_key=api_key,
                   username=username,
                   mode='online',
                   title='Comparison of Bulk Modulus and Shear Modulus',
                   x_title='Shear modulus (GPa)',
                   y_title='Bulk modulus (GPa)',
                   colorbar_title='Poisson Ratio',
                   fontfamily='Raleway',
                   fontscale=0.75,
                   fontcolor='#283747',
                   ticksize=30,
                   colorscale="Reds",
                   hovercolor='white',
                   hoverinfo='text',
                   bgcolor='#F4F6F6',
                   margins=110,
                   pad=10)

    pf.xy(('G_VRH', 'K_VRH'), labels='material_id', colors='poisson_ratio')


    # We can also use LaTeX if we use Plotly online/static
    pf.set_arguments(title="$\\text{Origin of Poisson Ratio } \\nu $",
                     y_title='$K_{VRH} \\text{(GPa)}$',
                     x_title='$G_{VRH} \\text{(GPa)}$',
                     colorbar_title='$\\nu$')
    pf.xy(('G_VRH', 'K_VRH'), labels='material_id', colors='poisson_ratio')
示例#7
0
def formatting_example(api_key, username):
    """
    Demonstrate common and advanced formatting features of PlotlyFig.

    PlotlyFig provides a set of arguments which make setting up good
    looking Plotly templates quick(er) and easy(er).

    Most formatting options can be set through the initializer of PlotlyFig.
    These options will remain the same for all figures producted, but you can
    change some common formatting options after instantitating a PlotlyFig
    object using set_arguments.

    Chart-specific formatting options can be passed to plotting methods.
    """

    if not api_key or not username:
        raise ValueError("Specify your Plotly api_key and username!")

    df = load_elastic_tensor()

    pf = PlotlyFig(df=df,
                   api_key=api_key,
                   username=username,
                   mode='online',
                   title='Comparison of Bulk Modulus and Shear Modulus',
                   x_title='Shear modulus (GPa)',
                   y_title='Bulk modulus (GPa)',
                   colorbar_title='Poisson Ratio',
                   fontfamily='Raleway',
                   fontscale=0.75,
                   fontcolor='#283747',
                   ticksize=30,
                   colorscale="Reds",
                   hovercolor='white',
                   hoverinfo='text',
                   bgcolor='#F4F6F6',
                   margins=110,
                   pad=10)

    pf.xy(('G_VRH', 'K_VRH'), labels='material_id', colors='poisson_ratio')

    # We can also use LaTeX if we use Plotly online/static
    pf.set_arguments(title="$\\text{Origin of Poisson Ratio } \\nu $",
                     y_title='$K_{VRH} \\text{(GPa)}$',
                     x_title='$G_{VRH} \\text{(GPa)}$',
                     colorbar_title='$\\nu$')
    pf.xy(('G_VRH', 'K_VRH'), labels='material_id', colors='poisson_ratio')
示例#8
0
def plot_bulk_shear_moduli():
    """
    Very basic example of xy scatter plot of Voigt-Reuss-Hill (VRH) average
        bulk vs. shear modulus. Poisson ratio as marker colors make the
        distinction between materials with different bulk/shear modulus ratios
    Returns:
        plotly plot in "offline" mode poped in the default browser.
    """
    df = load_elastic_tensor()
    pf = PlotlyFig(df,
                   y_title='Bulk Modulus (GPa)',
                   x_title='Shear Modulus (GPa)',
                   filename='bulk_shear_moduli')
    pf.xy(('G_VRH', 'K_VRH'),
          labels='material_id',
          colors='poisson_ratio',
          colorscale='Picnic')
示例#9
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']])
示例#10
0
def plot_scatter_matrix():
    """
    A few different scatter matrix plots using elastic dataset in matminer.
    Returns:
        plotly plot in "offline" mode opened in the default browser.
    """
    df = load_elastic_tensor()
    pf = PlotlyFig(df)

    # basic matrix:
    pf.scatter_matrix(cols=['K_VRH', 'G_VRH', 'nsites', 'volume'])

    # with colorscale and labels:
    pf.scatter_matrix(cols=['K_VRH', 'G_VRH', 'nsites', 'volume'],
                      colors='nsites',
                      labels='material_id',
                      colorscale='Picnic')

    # with all the numerical columns included (note the change in sizes):
    pf = PlotlyFig(filename='scatter_matrix_elastic', fontscale=0.6)
    pf.scatter_matrix(df, marker_scale=0.6)
示例#11
0
def plot_scatter_matrix():
    """
    A few different scatter matrix plots using elastic dataset in matminer.
    Returns:
        plotly plot in "offline" mode opened in the default browser.
    """
    df = load_elastic_tensor()
    pf = PlotlyFig(df)

    # basic matrix:
    pf.scatter_matrix(cols=['K_VRH', 'G_VRH', 'nsites', 'volume'])

    # with colorscale and labels:
    pf.scatter_matrix(cols=['K_VRH', 'G_VRH', 'nsites', 'volume'],
                      colors='nsites',
                      labels='material_id',
                      colorscale='Picnic')

    # with all the numerical columns included (note the change in sizes):
    pf = PlotlyFig(filename='scatter_matrix_elastic', fontscale=0.6)
    pf.scatter_matrix(df, marker_scale=0.6)
示例#12
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']])
示例#13
0
def simple_violin():
    df = load_elastic_tensor()
    pf = PlotlyFig(df, title="Distribution of Elastic Constant Averages",
                   colorscale='Reds')
    pf.violin(cols=['K_Reuss', 'K_Voigt', 'G_Reuss', 'G_Voigt'],
              use_colorscale=True)
示例#14
0
def plot_modes(api_key, username):
    """
    Demonstrate PlotlyFig plotting modes and show the easiest way to make
    adjustments.

    Offline mode - Set "mode" to "offline"
    Create a local html file. Note that offline mode in plotly disables LaTeX
    and some fonts on some systems by default. For the full-featured Plotly
    experience, please use the Plotly online mode.

    Static mode - Set "mode" to "static"
    Creates a single image file. Use height and width to specify the size of the
    image desired. api_key and username are required for static plotting mode.

    Online mode - Set "mode" to "online"
    Opens the figure in the Plotly online module.

    Notebook mode - Set "mode" to "notebook"
    Opens the figure in a Jupyter/IPython notebook. Not shown here, seen
    matminer_examples repository.

    Return mode - Pass "return_plot=True" into any plotting method
    Returns the figure as a 'bare-bones' dictionary. This can then be edited and
    passed into 'create_plot' of PlotlyFig or used directly with plotly.

    """

    if not api_key or not username:
        raise ValueError("Specify your Plotly api_key and username!")

    df = load_elastic_tensor()

    # First lets set uo our figure generally.
    pf = PlotlyFig(df,
                   title='Elastic data',
                   mode='offline',
                   x_scale='log',
                   y_scale='log')

    # Lets plot offline (the default) first. An html file will be created.
    pf.xy([('poisson_ratio', 'elastic_anisotropy')], labels='formula')

    # Now lets plot again, but changing the filename and without opening.
    # We do this with the 'set_arguments' method.
    pf.set_arguments(show_offline_plot=False, filename="myplot.html")
    pf.xy([('poisson_ratio', 'elastic_anisotropy')], labels='formula')

    # Now lets create a static image.
    pf.set_arguments(mode='static',
                     api_key=api_key,
                     username=username,
                     filename="my_PlotlyFig_plot.jpeg")
    pf.xy([('poisson_ratio', 'elastic_anisotropy')], labels='formula')
    # You can change the size of the image with the 'height' and 'width'
    # arguments to set_arguments.

    # Now we will use the Plotly online interface.
    pf.set_arguments(mode='online')
    pf.xy([('poisson_ratio', 'elastic_anisotropy')], labels='formula')

    # Great! Lets get the JSON representation of the PlotlyFig template as a
    # python dictionary. We can do this without changing the plot mode. From
    # any plotting method, simply pass 'return_plot=True' to return the plot.
    fig = pf.xy([('poisson_ratio', 'elastic_anisotropy')],
                labels='formula',
                return_plot=True)
    print("Here's our returned figure!")
    pprint.pprint(fig)

    # Edit the figure and plot it with the current plot mode (online):
    fig['layout']['hoverlabel']['bgcolor'] = 'pink'
    fig['layout']['title'] = 'My Custom Elastic Data Figure'
    pf.create_plot(fig)
def basic_parallel_coordinates():
    df = load_elastic_tensor()
    pf = PlotlyFig(df, title="Elastic tensor dataset", colorscale='Jet')
    pf.parallel_coordinates(colors='volume')
示例#16
0
def plot_modes(api_key, username):
    """
    Demonstrate PlotlyFig plotting modes and show the easiest way to make
    adjustments.

    Offline mode - Set "mode" to "offline"
    Create a local html file. Note that offline mode in plotly disables LaTeX
    and some fonts on some systems by default. For the full-featured Plotly
    experience, please use the Plotly online mode.

    Static mode - Set "mode" to "static"
    Creates a single image file. Use height and width to specify the size of the
    image desired. api_key and username are required for static plotting mode.

    Online mode - Set "mode" to "online"
    Opens the figure in the Plotly online module.

    Notebook mode - Set "mode" to "notebook"
    Opens the figure in a Jupyter/IPython notebook. Not shown here, seen
    matminer_examples repository.

    Return mode - Pass "return_plot=True" into any plotting method
    Returns the figure as a 'bare-bones' dictionary. This can then be edited and
    passed into 'create_plot' of PlotlyFig or used directly with plotly.

    """

    if not api_key or not username:
        raise ValueError("Specify your Plotly api_key and username!")

    df = load_elastic_tensor()

    # First lets set uo our figure generally.
    pf = PlotlyFig(df, title='Elastic data', mode='offline', x_scale='log',
                   y_scale='log')

    # Lets plot offline (the default) first. An html file will be created.
    pf.xy([('poisson_ratio', 'elastic_anisotropy')], labels='formula')

    # Now lets plot again, but changing the filename and without opening.
    # We do this with the 'set_arguments' method.
    pf.set_arguments(show_offline_plot=False, filename="myplot.html")
    pf.xy([('poisson_ratio', 'elastic_anisotropy')], labels='formula')

    # Now lets create a static image.
    pf.set_arguments(mode='static',
                     api_key=api_key,
                     username=username,
                     filename="my_PlotlyFig_plot.jpeg")
    pf.xy([('poisson_ratio', 'elastic_anisotropy')], labels='formula')
    # You can change the size of the image with the 'height' and 'width'
    # arguments to set_arguments.

    # Now we will use the Plotly online interface.
    pf.set_arguments(mode='online')
    pf.xy([('poisson_ratio', 'elastic_anisotropy')], labels='formula')

    # Great! Lets get the JSON representation of the PlotlyFig template as a
    # python dictionary. We can do this without changing the plot mode. From
    # any plotting method, simply pass 'return_plot=True' to return the plot.
    fig = pf.xy([('poisson_ratio', 'elastic_anisotropy')], labels='formula',
                return_plot=True)
    print("Here's our returned figure!")
    pprint.pprint(fig)

    # Edit the figure and plot it with the current plot mode (online):
    fig['layout']['hoverlabel']['bgcolor'] = 'pink'
    fig['layout']['title'] = 'My Custom Elastic Data Figure'
    pf.create_plot(fig)