B
    }d                 @   s   d Z ddlmZmZmZmZ ddlZddlmZm	Z
 ddlmZmZ dZdd ZdddZG dd de
jZG dd deZee dS )zdThis module redefines the matplotlib log scale to give a more
helpful set of major and minor ticks.
    )ceilflooriscloselogN)rcParamsticker)LogScaleregister_scalez(Duncan Macleod <duncan.macleod@ligo.org>c             C   s    t d rd|  dS d|  dS )Nztext.usetex$z$\mathdefault{z}$)r   )s r   Z/work/yifan.wang/ringdown/master-ringdown-env/lib/python3.7/site-packages/gwpy/plot/log.py_math"   s    r      顆 c             C   s2   | j o0t| dk o0|  |k o0t| | |S )Nr   )sizeallmaxnumpyZarray_equalround)valuesZndecZthreshr   r   r   _render_simple(   s    r   c                   sD   e Zd ZdZ fddZdd Zd fdd	Zd fd	d
	Z  ZS )LogFormattera  Format values for log axis.

    This `LogFormatter` extends the standard
    `~matplotlib.ticker.LogFormatterMathtext` to print numbers in the
    range [0.01, 1000) normally, and all others via the standard
    `~matplotlib.ticker.LogFormatterMathtext` output.
    c                sH     | tdd |D }t|r< fddt|D S t |S )Nc             S   s   g | ]}t |d qS )z.12g)float).0xr   r   r   
<listcomp>B   s    z-LogFormatter.format_ticks.<locals>.<listcomp>c                s.   g | ]&\}} |  rt|n||d dqS )z%s)posfmt)
is_integerint)r   ir   )selfr   r   r   G   s   )set_locsr   Z
asanyarrayr   	enumeratesuperformat_ticks)r"   r   Zvalues2)	__class__)r"   r   r&   9   s    

zLogFormatter.format_ticksc             C   s:   | j  }t|}tjt|d tt|d tdjS )Nr      )Zdtype)	axisZget_view_intervalr   log10Zaranger   r   r    r   )r"   ZviewlimZloglimr   r   r   
_num_ticksM   s    


zLogFormatter._num_ticksNc                s@   t  j|d}|  dkr<| jdhkr<| jdkr<dddh| _|S )N)locsr(   
   g      ?g      @g      $@)r%   r#   r+   
_sublabels_base)r"   r,   ret)r'   r   r   r#   V   s    
zLogFormatter.set_locsc                s   |st |pdd S |dk r dnd}t|}| j}t|t| }t|t|}| jr^|s^dS |rlt|nt|}t|||  }	| 	 }
|
dkr| j
d k	r|	| j
krdS |rt |||  S t j||dS )Nz%sr   - r(   )r   )r   absr/   r   r   r   labelOnlyBaser   r   r+   r.   r%   __call__)r"   r   r   r   signbZfxZis_x_decadeexponentZcoeffZnticks)r'   r   r   r5   e   s&    


zLogFormatter.__call__)N)NN)	__name__
__module____qualname____doc__r&   r+   r#   r5   __classcell__r   r   )r'   r   r   1   s
   	r   c               @   s   e Zd ZdZdd ZdS )r   zGWpy version of the matplotlib `LogScale`.

    This scale overrides the default to use the new GWpy formatters
    for major and minor ticks.
    c             C   sV   | t| j |t| j |t| j| j |t| j| jd k	d d S )N)r4   )	Zset_major_locatormtickerZ
LogLocatorbaseZset_major_formatterr   Zset_minor_locatorsubsZset_minor_formatter)r"   r)   r   r   r   #set_default_locators_and_formatters   s
    z,LogScale.set_default_locators_and_formattersN)r9   r:   r;   r<   rA   r   r   r   r   r      s   r   )r   r   )r<   mathr   r   r   r   r   Z
matplotlibr   r   r>   Zmatplotlib.scaler   Z	_LogScaler	   
__author__r   r   ZLogFormatterMathtextr   r   r   r   r   <module>   s   
	V