Example #1
0
 def grid_iterate(i, grid_dict, name, parent_params):
     key = iterable_keys[i]
     name = key if name is None else name + "-" + key
     print("name: {}".format(name))
     if i < len(iterable_keys) - 1:
         name += "("
         for j in grid_dict[key]:
             settings[key] = j
             # track parents and their values for given run
             parent_params = parent_params.copy()
             parent_params[key] = j
             paren_i = name.rfind("(")
             if paren_i != -1:
                 name = name[:paren_i]
             if libmag.is_number(j):
                 name += "({:.3g})".format(j)
             else:
                 name += " {}".format(j)
             grid_iterate(i + 1, grid_dict, name, parent_params)
     else:
         # process each value in parameter array
         stats = []
         last_param_vals = grid_dict[key]
         for param in last_param_vals:
             print("===============================================\n"
                   "Grid search hyperparameters {} for {}".format(
                       name, libmag.format_num(param, 3)))
             settings[key] = param
             stat, summaries = fnc(*fnc_args)
             stats.append(stat)
             file_summaries.extend(summaries)
         iterable_dict[name] = (stats, last_param_vals, key, parent_params)
Example #2
0
    def color_picker_changed(self, text):
        """Respond to color picker :class:`TextBox` changes by updating
        the specified intensity value in all plot editors.

        Args:
            text (str): String of text box value. Converted to an int if
                non-empty.
        """
        intensity = text
        if text:
            if not libmag.is_number(intensity): return
            intensity = int(intensity)
        print("updating specified color to", intensity)
        for i, ed in enumerate(self.plot_eds.values()):
            ed.intensity_spec = intensity
def scale_xticks(
        ax: "axes.Axes", rotation: float,
        x_labels: Optional[Sequence[Any]] = None):
    """Draw x-tick labels with smaller font for increasing number of labels.
    
    Args:
        ax: Matplotlib axes.
        rotation: Label rotation angle.
        x_labels: X-axis labels; defaults to None, in which case the current
            labels will be used.

    """
    if x_labels is None:
        # default to use existing labels
        x_labels = ax.get_xticklabels()
    
    font_size = plt.rcParams["axes.titlesize"]
    if libmag.is_number(font_size):
        # scale font size of x-axis labels by a sigmoid function to rapidly 
        # decrease size for larger numbers of labels so they don't overlap
        font_size *= (math.atan(len(x_labels) / 10 - 5) * -2 / math.pi + 1) / 2
    font_dict = {"fontsize": font_size}
    
    # draw x-ticks based on number of bars per group and align to right 
    # since center shifts the horiz middle of the label to the center; 
    # rotation_mode in dict helps but still slightly off
    ax.set_xticklabels(
        x_labels, rotation=rotation, horizontalalignment="right", 
        fontdict=font_dict)
    
    # translate to right since "right" alignment shift the right of labels 
    # too far to the left of tick marks; shift less with more groups
    offset = transforms.ScaledTranslation(
        30 / np.cbrt(len(x_labels)) / ax.figure.dpi, 0,
        ax.figure.dpi_scale_trans)
    for lbl in ax.xaxis.get_majorticklabels():
        lbl.set_transform(lbl.get_transform() + offset)
Example #4
0
 def test_is_number(self):
     self.assertEqual(libmag.is_number(5), True)
     self.assertEqual(libmag.is_number(5.4), True)
     self.assertEqual(libmag.is_number("string"), False)