<s> from __future__ import division <EOL> from future . builtins import str <EOL> import numpy as np <EOL> import matplotlib . pyplot as plt <EOL> __all__ = [ '<STR_LIT>' ] <EOL> def slope_marker ( origin , slope , invert = False , size_frac = <NUM_LIT:0.1> , pad_frac = <NUM_LIT> , <EOL> text_kwargs = None , poly_kwargs = None , ax = None ) : <EOL> """<STR_LIT>""" <EOL> ax = ax if ax is not None else plt . gca ( ) <EOL> text_kwargs = { } if text_kwargs is None else text_kwargs <EOL> poly_kwargs = { } if poly_kwargs is None else poly_kwargs <EOL> if np . iterable ( slope ) : <EOL> rise , run = slope <EOL> slope = float ( rise ) / run <EOL> else : <EOL> rise = run = None <EOL> x0 , y0 = origin <EOL> xlim = ax . get_xlim ( ) <EOL> dx_linear = size_frac * ( xlim [ <NUM_LIT:1> ] - xlim [ <NUM_LIT:0> ] ) <EOL> dx_decades = size_frac * ( np . log10 ( xlim [ <NUM_LIT:1> ] ) - np . log10 ( xlim [ <NUM_LIT:0> ] ) ) <EOL> if invert : <EOL> dx_linear = - dx_linear <EOL> dx_decades = - dx_decades <EOL> if ax . get_xscale ( ) == '<STR_LIT>' : <EOL> log_size = dx_decades <EOL> dx = log_displace ( x0 , log_size ) - x0 <EOL> x_run = _text_position ( x0 , log_size / <NUM_LIT> , scale = '<STR_LIT>' ) <EOL> x_rise = _text_position ( x0 + dx , dx_decades * pad_frac , scale = '<STR_LIT>' ) <EOL> else : <EOL> dx = dx_linear <EOL> x_run = _text_position ( x0 , dx / <NUM_LIT> ) <EOL> x_rise = _text_position ( x0 + dx , pad_frac * dx ) <EOL> if ax . get_yscale ( ) == '<STR_LIT>' : <EOL> log_size = dx_decades * slope <EOL> dy = log_displace ( y0 , log_size ) - y0 <EOL> y_run = _text_position ( y0 , - dx_decades * slope * pad_frac , scale = '<STR_LIT>' ) <EOL> y_rise = _text_position ( y0 , log_size / <NUM_LIT> , scale = '<STR_LIT>' ) <EOL> else : <EOL> dy = dx_linear * slope <EOL> y_run = _text_position ( y0 , - ( pad_frac * dy ) ) <EOL> y_rise = _text_position ( y0 , dy / <NUM_LIT> ) <EOL> x_pad = pad_frac * dx <EOL> y_pad = pad_frac * dy <EOL> va = '<STR_LIT>' if y_pad > <NUM_LIT:0> else '<STR_LIT>' <EOL> ha = '<STR_LIT:left>' if x_pad > <NUM_LIT:0> else '<STR_LIT:right>' <EOL> if rise is not None : <EOL> ax . text ( x_run , y_run , str ( run ) , va = va , ha = '<STR_LIT>' , ** text_kwargs ) <EOL> ax . text ( x_rise , y_rise , str ( rise ) , ha = ha , va = '<STR_LIT>' , ** text_kwargs ) <EOL> else : <EOL> ax . text ( x_rise , y_rise , str ( slope ) , ha = ha , va = '<STR_LIT>' , ** text_kwargs ) <EOL> ax . add_patch ( _slope_triangle ( origin , dx , dy , ** poly_kwargs ) ) <EOL> def log_displace ( x0 , dx_log ) : <EOL> """<STR_LIT>""" <EOL> return <NUM_LIT:10> ** ( np . log10 ( x0 ) + dx_log ) <EOL> def _text_position ( x0 , dx , scale = '<STR_LIT>' ) : <EOL> if scale == '<STR_LIT>' : <EOL> return x0 + dx <EOL> elif scale == '<STR_LIT>' : <EOL> return log_displace ( x0 , dx ) <EOL> else : <EOL> raise ValueError ( '<STR_LIT>' % scale ) <EOL> def _slope_triangle ( origin , dx , dy , fc = '<STR_LIT>' , ** poly_kwargs ) : <EOL> """<STR_LIT>""" <EOL> if '<STR_LIT>' not in poly_kwargs and '<STR_LIT>' not in poly_kwargs : <EOL> poly_kwargs [ '<STR_LIT>' ] = '<STR_LIT:none>' <EOL> if '<STR_LIT>' not in poly_kwargs and '<STR_LIT>' not in poly_kwargs : <EOL> poly_kwargs [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> verts = [ np . asarray ( origin ) ] <EOL> verts . append ( verts [ <NUM_LIT:0> ] + ( dx , <NUM_LIT:0> ) ) <EOL> verts . append ( verts [ <NUM_LIT:0> ] + ( dx , dy ) ) <EOL> return plt . Polygon ( verts , ** poly_kwargs ) </s>
