Python Examples

The following are code examples for showing how to use They are from open source Python projects. You can vote up the examples you like or vote down the ones you don't like.

Example 1
Project: PyGauss   Author: chrisjsewell   File:    GNU General Public License v3.0 5 votes vote down vote up
def _get_charge_colors(self, relative=False, minval=-1, maxval=1, alpha=None):
        charges = self._read_data('_nbo_data', 'atomcharges')['natural']
        if relative: minval, maxval = (min(charges), max(charges))
        norm = mpl.colors.Normalize(vmin=minval, vmax=maxval)
        cmap = cm.bwr
        m = cm.ScalarMappable(norm=norm, cmap=cmap)
        colors=m.to_rgba(charges, alpha=alpha, bytes=True)
        return colors 
Example 2
Project: HINT   Author: MichaelDoron   File:    BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
def plot_interaction_map(model, name, matrix, output_name, first_variable, second_variable, x_coord, y_coord, output_path):
  Plots a map of the parameter space for two input parameters, with the areas with more nonlinearity colored white
  :param ax: The axes on which to plot
  :param args: The arguments for the plot - 
                 The matrix to plot,
                 the name of the first variable
                 The name of the second variable,
                 The name of the first variable, as a key to the parameter limits dictionary
                 The name of the second variable, as a key to the parameter limits dictionary
                 the x coordinate of the sample being studied
                 the y coordinate of the sample being studied
  :returns: The axes with the plotted sample
  import matplotlib
  import as cm
  import matplotlib.pyplot as plt

  font = {'size'   : 14}

  matplotlib.rc('font', **font)
  fig = plt.figure(figsize=(5,5))
  ax = plt.subplot()

  maxValue = np.max(np.abs(matrix))
  img = ax.imshow((matrix), cmap = cm.bwr, origin='lower', vmin = -min(maxValue, 6), vmax = min(maxValue, 6), interpolation='spline16')

  first_variable = '{}'.format(first_variable)
  second_variable = '{}'.format(second_variable)
  ax.set_ylabel(r'$x_i$ = ' + first_variable)
  ax.set_xlabel(r'$y_i$ = ' + second_variable)
  ax.axes.set_xticks([0, 50, 99])
  ax.axes.set_yticks([0, 50, 99])
  xticks = np.linspace(np.array(model.feature_limits[first_variable]).min(), np.array(model.feature_limits[first_variable]).max(), 3)
  yticks = np.linspace(np.array(model.feature_limits[second_variable]).min(), np.array(model.feature_limits[second_variable]).max(), 3)
  ax.scatter([x_coord], [y_coord], marker='o', color='white', s = 250, edgecolors='black', linewidth=3)

  ax.set_yticklabels([xticks[tind] for tind in range(3)])
  ax.set_xticklabels([yticks[tind] for tind in range(3)])
  ax.axis([0, (100) - 1, 0, (100) - 1])

  # ax.scatter([x_coord_linear], [y_coord_linear], marker='o', color='blue', s = 250, edgecolors='black', linewidth=3)
  t = ax.set_title(r'$\mathregular{\frac{\delta ^2 F(\bar{x})}{\delta x_i \delta x_j}}$')
  # t = ax.set_title('{} and {} - '.format(first_variable, second_variable) + r'$\mathregular{\frac{\delta ^2 F(\bar{x})}{\delta x_i \delta x_j}}$')
  t.set_position([.5, 1.025])
  from mpl_toolkits.axes_grid1 import make_axes_locatable
  divider = make_axes_locatable(ax)
  cax = divider.append_axes("right", size="5%", pad=0.05)
  cb = plt.colorbar(img, cax=cax)
  cb.set_label("Nomralized mixed derivative", rotation=90)
  plt.savefig('{}/{}_{}_{}_{}_nonlinear_map.pdf'.format(output_path, name, output_name, first_variable, second_variable), transparent=True, bbox_inches='tight', format='pdf', dpi=600)
  # plt.close('all')