Пример #1
0
def update_ticks(axes, coord, components, is_log):
    """
    Changes the axes to have the proper tick formatting based on the type of
    component.

    Returns `None` or the number of categories if components is Categorical.

    Parameters
    ----------
    axes : `~matplotlib.axes.Axes`
        A matplotlib axis object to alter
    coord : { 'x' | 'y' }
        The coordinate axis on which to update the ticks
    components : iterable
        A list of components that are plotted along this axis
    if_log : boolean
        Whether the axis has a log-scale
    """

    if coord == 'x':
        axis = axes.xaxis
    elif coord == 'y':
        axis = axes.yaxis
    else:
        raise TypeError("coord must be one of x,y")

    is_cat = any(comp.categorical for comp in components)
    is_date = any(comp.datetime for comp in components)

    if is_date:
        loc = AutoDateLocator()
        fmt = AutoDateFormatter(loc)
        axis.set_major_locator(loc)
        axis.set_major_formatter(fmt)
    elif is_log:
        axis.set_major_locator(LogLocator())
        axis.set_major_formatter(LogFormatterMathtext())
    elif is_cat:
        all_categories = np.empty((0,), dtype=np.object)
        for comp in components:
            all_categories = np.union1d(comp.categories, all_categories)
        locator = MaxNLocator(10, integer=True)
        locator.view_limits(0, all_categories.shape[0])
        format_func = partial(tick_linker, all_categories)
        formatter = FuncFormatter(format_func)

        axis.set_major_locator(locator)
        axis.set_major_formatter(formatter)
        return all_categories.shape[0]
    else:
        axis.set_major_locator(AutoLocator())
        axis.set_major_formatter(ScalarFormatter())
Пример #2
0
def update_ticks(axes, coord, components, is_log):
    """
    Changes the axes to have the proper tick formatting based on the type of
    component.

    :param axes: A matplotlib axis object to alter
    :param coord: 'x' or 'y'
    :param components: A list() of components that are plotted along this axis
    :param is_log: Boolean for log-scale.
    :kwarg max_categories: The maximum number of categories to display.
    :return: None or #categories if components is Categorical
    """

    if coord == 'x':
        axis = axes.xaxis
    elif coord == 'y':
        axis = axes.yaxis
    else:
        raise TypeError("coord must be one of x,y")

    is_cat = all(comp.categorical for comp in components)
    if is_log:
        axis.set_major_locator(LogLocator())
        axis.set_major_formatter(LogFormatterMathtext())
    elif is_cat:
        all_categories = np.empty((0,), dtype=np.object)
        for comp in components:
            all_categories = np.union1d(comp.categories, all_categories)
        locator = MaxNLocator(10, integer=True)
        locator.view_limits(0, all_categories.shape[0])
        format_func = partial(tick_linker, all_categories)
        formatter = FuncFormatter(format_func)

        axis.set_major_locator(locator)
        axis.set_major_formatter(formatter)
        return all_categories.shape[0]
    else:
        axis.set_major_locator(AutoLocator())
        axis.set_major_formatter(ScalarFormatter())
Пример #3
0
    else:
        fig = plotG_one(n-1, r, clens, drawraw=args.drawraw,rawcolor=rawclr,
                        smoothcolor=smoothclr, smoothwidth=smoothwidth,
                        maxgap=args.maxgap) 
        if args.maxmin:
            fillbetween_chrom(r.coords[n-1], r.maxminG[n-1], maxgap=args.maxgap, alpha=0.5)

    ax = fig.gca()
    if 'coords' in vars(args):
        ax.set_xlim(*args.coords)

    if n > 0:
        if 'nticks' in vars(args):
            m = MaxNLocator(*args.nticks)
            m.view_limits(*ax.get_xlim())
            ax.xaxis.set_major_locator(m)
        else:
            ax.xaxis.set_major_locator(MaxNLocator(4))

    if 'ylim' in vars(args):
        ax.set_ylim(*args.ylim)
    if 'figsize' in vars(args):
        fig.set_size_inches(*args.figsize)

    if args.threshold > 0:
        ax.hlines(args.threshold, 0, tlen,  color=args.thresholdclr, linestyle='dashed')
    
    name,ext = os.path.splitext(args.outfile)
    # check extension of outfile
    if ext in ('.png','.pdf','.jpg','.ps','.eps','.svg'):
Пример #4
0
def update_ticks(axes, coord, kinds, is_log, categories, projection='rectilinear', radians=True, label=None):
    """
    Changes the axes to have the proper tick formatting based on the type of
    component.

    Returns `None` or the number of categories if components is Categorical.

    Parameters
    ----------
    axes : :class:`matplotlib.axes.Axes`
        A matplotlib axis object to alter
    coord : { 'x' | 'y' }
        The coordinate axis on which to update the ticks
    components : iterable
        A list of components that are plotted along this axis
    if_log : boolean
        Whether the axis has a log-scale
    projection: str
        The name of the matplotlib projection for the axes object. Defaults to 'rectilinear'.
        Currently only the scatter viewer supports different projections.
    """

    # Short circuit the full-sphere projections
    if projection in ['aitoff', 'hammer', 'mollweide', 'lambert']:
        return

    if coord == 'x':
        axis = axes.xaxis
    elif coord == 'y':
        axis = axes.yaxis
    else:
        raise TypeError("coord must be one of x,y")

    is_cat = 'categorical' in kinds
    is_date = 'datetime' in kinds

    if is_date:
        loc = AutoDateLocator()
        fmt = AutoDateFormatter(loc)
        axis.set_major_locator(loc)
        axis.set_major_formatter(fmt)
    elif is_log:
        axis.set_major_locator(LogLocator())
        axis.set_major_formatter(LogFormatterMathtext())
    elif is_cat:
        locator = MaxNLocator(10, integer=True)
        locator.view_limits(0, categories.shape[0])
        format_func = partial(tick_linker, categories)
        formatter = FuncFormatter(format_func)
        axis.set_major_locator(locator)
        axis.set_major_formatter(formatter)
    # Have to treat the axes for polar plots differently
    elif projection == 'polar':
        if coord == 'x':
            axis.set_major_locator(ThetaLocator(AutoLocator()))
            formatter_type = ThetaRadianFormatter if radians else ThetaDegreeFormatter
            axis.set_major_formatter(formatter_type(label))
            for lbl, loc in zip(axis.get_majorticklabels(), axis.get_majorticklocs()):
                lbl.set_horizontalalignment(polar_tick_alignment(loc, radians))
        else:
            axis.set_major_locator(AutoLocator())
            axis.set_major_formatter(PolarRadiusFormatter(label))
            for lbl in axis.get_majorticklabels():
                lbl.set_fontstyle("italic")
    else:
        axis.set_major_locator(AutoLocator())
        axis.set_major_formatter(ScalarFormatter())
Пример #5
0
    if n <= 0:
        fig = plotG_all(r, clens, drawraw=args.drawraw,rawcolor=rawclr,
                        smoothcolor=smoothclr, smoothwidth=smoothwidth,
                        maxgap=args.maxgap) 
    else:
        fig = plotG_one(n-1, r, clens, drawraw=args.drawraw,rawcolor=rawclr,
                        smoothcolor=smoothclr, smoothwidth=smoothwidth,
                        maxgap=args.maxgap) 
    ax = fig.gca()
    if 'coords' in vars(args):
        ax.set_xlim(*args.coords)

    if n > 0:
        if 'nticks' in vars(args):
            m = MaxNLocator(*args.nticks)
            m.view_limits(*ax.get_xlim())
            ax.xaxis.set_major_locator(m)
        else:
            ax.xaxis.set_major_locator(MaxNLocator(4))

    if 'ylim' in vars(args):
        ax.set_ylim(*args.ylim)
    if 'figsize' in vars(args):
        fig.set_size_inches(*args.figsize)

    if args.threshold > 0:
        ax.hlines(args.threshold, 0, tlen,  color=args.thresholdclr, linestyle='dashed')
    
    name,ext = os.path.splitext(args.outfile.name)
    # check extension of outfile
    if ext in ('.png','.pdf','.jpg','.ps','.eps','.svg'):