<s> import numpy as np <EOL> from statsmodels . compat import range <EOL> from . import utils <EOL> def dot_plot ( points , intervals = None , lines = None , sections = None , <EOL> styles = None , marker_props = None , line_props = None , <EOL> split_names = None , section_order = None , line_order = None , <EOL> stacked = False , styles_order = None , striped = False , <EOL> horizontal = True , show_names = "<STR_LIT>" , <EOL> fmt_left_name = None , fmt_right_name = None , <EOL> show_section_titles = None , ax = None ) : <EOL> """<STR_LIT>""" <EOL> import matplotlib . transforms as transforms <EOL> fig , ax = utils . create_mpl_ax ( ax ) <EOL> points = np . asarray ( points ) <EOL> asarray_or_none = lambda x : None if x is None else np . asarray ( x ) <EOL> intervals = asarray_or_none ( intervals ) <EOL> lines = asarray_or_none ( lines ) <EOL> sections = asarray_or_none ( sections ) <EOL> styles = asarray_or_none ( styles ) <EOL> npoint = len ( points ) <EOL> if lines is None : <EOL> lines = np . arange ( npoint ) <EOL> if sections is None : <EOL> sections = np . zeros ( npoint ) <EOL> if styles is None : <EOL> styles = np . zeros ( npoint ) <EOL> section_title_space = <NUM_LIT:0.5> <EOL> nsect = len ( set ( sections ) ) <EOL> if section_order is not None : <EOL> nsect = len ( set ( section_order ) ) <EOL> if show_section_titles == False : <EOL> draw_section_titles = False <EOL> nsect_title = <NUM_LIT:0> <EOL> elif show_section_titles == True : <EOL> draw_section_titles = True <EOL> nsect_title = nsect <EOL> else : <EOL> draw_section_titles = nsect > <NUM_LIT:1> <EOL> nsect_title = nsect if nsect > <NUM_LIT:1> else <NUM_LIT:0> <EOL> section_space_total = section_title_space * nsect_title <EOL> ax . set_xmargin ( <NUM_LIT> ) <EOL> ax . set_ymargin ( <NUM_LIT> ) <EOL> if section_order is None : <EOL> lines0 = list ( set ( sections ) ) <EOL> lines0 . sort ( ) <EOL> else : <EOL> lines0 = section_order <EOL> if line_order is None : <EOL> lines1 = list ( set ( lines ) ) <EOL> lines1 . sort ( ) <EOL> else : <EOL> lines1 = line_order <EOL> lines_map = { } <EOL> for i in range ( npoint ) : <EOL> if section_order is not None and sections [ i ] not in section_order : <EOL> continue <EOL> if line_order is not None and lines [ i ] not in line_order : <EOL> continue <EOL> ky = ( sections [ i ] , lines [ i ] ) <EOL> if ky not in lines_map : <EOL> lines_map [ ky ] = [ ] <EOL> lines_map [ ky ] . append ( i ) <EOL> bbox = ax . get_window_extent ( ) . transformed ( <EOL> fig . dpi_scale_trans . inverted ( ) ) <EOL> awidth , aheight = bbox . width , bbox . height <EOL> nrows = len ( lines_map ) <EOL> bottom , top = <NUM_LIT:0> , <NUM_LIT:1> <EOL> if horizontal : <EOL> trans = transforms . blended_transform_factory ( ax . transData , <EOL> ax . transAxes ) <EOL> else : <EOL> trans = transforms . blended_transform_factory ( ax . transAxes , <EOL> ax . transData ) <EOL> title_space_axes = section_title_space / aheight <EOL> if horizontal : <EOL> dpos = ( top - bottom - nsect_title * title_space_axes ) / float ( nrows ) <EOL> else : <EOL> dpos = ( top - bottom ) / float ( nrows ) <EOL> if styles_order is not None : <EOL> style_codes = styles_order <EOL> else : <EOL> style_codes = list ( set ( styles ) ) <EOL> style_codes . sort ( ) <EOL> if horizontal : <EOL> style_codes = style_codes [ : : - <NUM_LIT:1> ] <EOL> nval = len ( style_codes ) <EOL> if nval > <NUM_LIT:1> : <EOL> stackd = dpos / ( <NUM_LIT> * ( float ( nval ) - <NUM_LIT:1> ) ) <EOL> else : <EOL> stackd = <NUM_LIT:0.> <EOL> style_codes_map = dict ( ( x , style_codes . index ( x ) ) for x in style_codes ) <EOL> colors = [ "<STR_LIT:r>" , "<STR_LIT:g>" , "<STR_LIT:b>" , "<STR_LIT:y>" , "<STR_LIT:k>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> if marker_props is None : <EOL> marker_props = dict ( ( x , { } ) for x in style_codes ) <EOL> for j in range ( nval ) : <EOL> sc = style_codes [ j ] <EOL> if "<STR_LIT>" not in marker_props [ sc ] : <EOL> marker_props [ sc ] [ "<STR_LIT>" ] = colors [ j % len ( colors ) ] <EOL> if "<STR_LIT>" not in marker_props [ sc ] : <EOL> marker_props [ sc ] [ "<STR_LIT>" ] = "<STR_LIT:o>" <EOL> if "<STR_LIT>" not in marker_props [ sc ] : <EOL> marker_props [ sc ] [ "<STR_LIT>" ] = <NUM_LIT:10> if stackd == <NUM_LIT:0> else <NUM_LIT:6> <EOL> if line_props is None : <EOL> line_props = dict ( ( x , { } ) for x in style_codes ) <EOL> for j in range ( nval ) : <EOL> sc = style_codes [ j ] <EOL> if "<STR_LIT>" not in line_props [ sc ] : <EOL> line_props [ sc ] [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> if "<STR_LIT>" not in line_props [ sc ] : <EOL> line_props [ sc ] [ "<STR_LIT>" ] = <NUM_LIT:2> if stackd > <NUM_LIT:0> else <NUM_LIT:8> <EOL> if horizontal : <EOL> pos = top - dpos / <NUM_LIT:2> if nsect == <NUM_LIT:1> else top <EOL> else : <EOL> pos = bottom + dpos / <NUM_LIT:2> <EOL> labeled = set ( ) <EOL> ticks = [ ] <EOL> for k0 in lines0 : <EOL> if draw_section_titles : <EOL> if horizontal : <EOL> y0 = pos + dpos / <NUM_LIT:2> if k0 == lines0 [ <NUM_LIT:0> ] else pos <EOL> ax . fill_between ( ( <NUM_LIT:0> , <NUM_LIT:1> ) , ( y0 , y0 ) , <EOL> ( pos - <NUM_LIT> * title_space_axes , <EOL> pos - <NUM_LIT> * title_space_axes ) , <EOL> color = '<STR_LIT>' , <EOL> transform = ax . transAxes , <EOL> zorder = <NUM_LIT:1> ) <EOL> txt = ax . text ( <NUM_LIT:0.5> , pos - <NUM_LIT> * title_space_axes , k0 , <EOL> horizontalalignment = '<STR_LIT>' , <EOL> verticalalignment = '<STR_LIT>' , <EOL> transform = ax . transAxes ) <EOL> txt . set_fontweight ( "<STR_LIT>" ) <EOL> pos -= title_space_axes <EOL> else : <EOL> m = len ( [ k for k in lines_map if k [ <NUM_LIT:0> ] == k0 ] ) <EOL> ax . fill_between ( ( pos - dpos / <NUM_LIT:2> + <NUM_LIT> , <EOL> pos + ( m - <NUM_LIT:1> ) * dpos + dpos / <NUM_LIT:2> - <NUM_LIT> ) , <EOL> ( <NUM_LIT> , <NUM_LIT> ) , ( <NUM_LIT> , <NUM_LIT> ) , <EOL> color = '<STR_LIT>' , <EOL> transform = ax . transAxes , <EOL> zorder = <NUM_LIT:1> , clip_on = False ) <EOL> txt = ax . text ( pos + ( m - <NUM_LIT:1> ) * dpos / <NUM_LIT:2> , <NUM_LIT> , k0 , <EOL> horizontalalignment = '<STR_LIT>' , <EOL> verticalalignment = '<STR_LIT>' , <EOL> transform = ax . transAxes ) <EOL> txt . set_fontweight ( "<STR_LIT>" ) <EOL> jrow = <NUM_LIT:0> <EOL> for k1 in lines1 : <EOL> if ( k0 , k1 ) not in lines_map : <EOL> continue <EOL> if horizontal : <EOL> ax . axhline ( pos , color = '<STR_LIT>' ) <EOL> else : <EOL> ax . axvline ( pos , color = '<STR_LIT>' ) <EOL> if split_names is not None : <EOL> us = k1 . split ( split_names ) <EOL> if len ( us ) >= <NUM_LIT:2> : <EOL> left_label , right_label = us [ <NUM_LIT:0> ] , us [ <NUM_LIT:1> ] <EOL> else : <EOL> left_label , right_label = k1 , None <EOL> else : <EOL> left_label , right_label = k1 , None <EOL> if fmt_left_name is not None : <EOL> left_label = fmt_left_name ( left_label ) <EOL> if fmt_right_name is not None : <EOL> right_label = fmt_right_name ( right_label ) <EOL> if striped and jrow % <NUM_LIT:2> == <NUM_LIT:0> : <EOL> if horizontal : <EOL> ax . fill_between ( ( <NUM_LIT:0> , <NUM_LIT:1> ) , ( pos - dpos / <NUM_LIT:2> , pos - dpos / <NUM_LIT:2> ) , <EOL> ( pos + dpos / <NUM_LIT:2> , pos + dpos / <NUM_LIT:2> ) , <EOL> color = '<STR_LIT>' , <EOL> transform = ax . transAxes , <EOL> zorder = <NUM_LIT:0> ) <EOL> else : <EOL> ax . fill_between ( ( pos - dpos / <NUM_LIT:2> , pos + dpos / <NUM_LIT:2> ) , <EOL> ( <NUM_LIT:0> , <NUM_LIT:0> ) , ( <NUM_LIT:1> , <NUM_LIT:1> ) , <EOL> color = '<STR_LIT>' , <EOL> transform = ax . transAxes , <EOL> zorder = <NUM_LIT:0> ) <EOL> jrow += <NUM_LIT:1> <EOL> if show_names . lower ( ) in ( "<STR_LIT:left>" , "<STR_LIT>" ) : <EOL> if horizontal : <EOL> ax . text ( - <NUM_LIT:0.1> / awidth , pos , left_label , <EOL> horizontalalignment = "<STR_LIT:right>" , <EOL> verticalalignment = '<STR_LIT>' , <EOL> transform = ax . transAxes , <EOL> family = '<STR_LIT>' ) <EOL> else : <EOL> ax . text ( pos , - <NUM_LIT:0.1> / aheight , left_label , <EOL> horizontalalignment = "<STR_LIT>" , <EOL> verticalalignment = '<STR_LIT>' , <EOL> transform = ax . transAxes , <EOL> family = '<STR_LIT>' ) <EOL> if show_names . lower ( ) in ( "<STR_LIT:right>" , "<STR_LIT>" ) : <EOL> if right_label is not None : <EOL> if horizontal : <EOL> ax . text ( <NUM_LIT:1> + <NUM_LIT:0.1> / awidth , pos , right_label , <EOL> horizontalalignment = "<STR_LIT:left>" , <EOL> verticalalignment = '<STR_LIT>' , <EOL> transform = ax . transAxes , <EOL> family = '<STR_LIT>' ) <EOL> else : <EOL> ax . text ( pos , <NUM_LIT:1> + <NUM_LIT:0.1> / aheight , right_label , <EOL> horizontalalignment = "<STR_LIT>" , <EOL> verticalalignment = '<STR_LIT>' , <EOL> transform = ax . transAxes , <EOL> family = '<STR_LIT>' ) <EOL> ticks . append ( pos ) <EOL> for ji , jp in enumerate ( lines_map [ ( k0 , k1 ) ] ) : <EOL> yo = <NUM_LIT:0> <EOL> if stacked : <EOL> yo = - dpos / <NUM_LIT:5> + style_codes_map [ styles [ jp ] ] * stackd <EOL> pt = points [ jp ] <EOL> if intervals is not None : <EOL> if np . isscalar ( intervals [ jp ] ) : <EOL> lcb , ucb = pt - intervals [ jp ] , pt + intervals [ jp ] <EOL> else : <EOL> lcb , ucb = pt - intervals [ jp ] [ <NUM_LIT:0> ] , pt + intervals [ jp ] [ <NUM_LIT:1> ] <EOL> if horizontal : <EOL> ax . plot ( [ lcb , ucb ] , [ pos + yo , pos + yo ] , '<STR_LIT:->' , <EOL> transform = trans , <EOL> ** line_props [ styles [ jp ] ] ) <EOL> else : <EOL> ax . plot ( [ pos + yo , pos + yo ] , [ lcb , ucb ] , '<STR_LIT:->' , <EOL> transform = trans , <EOL> ** line_props [ styles [ jp ] ] ) <EOL> sl = styles [ jp ] <EOL> sll = sl if sl not in labeled else None <EOL> labeled . add ( sl ) <EOL> if horizontal : <EOL> ax . plot ( [ pt , ] , [ pos + yo , ] , ls = '<STR_LIT:None>' , <EOL> transform = trans , label = sll , <EOL> ** marker_props [ sl ] ) <EOL> else : <EOL> ax . plot ( [ pos + yo , ] , [ pt , ] , ls = '<STR_LIT:None>' , <EOL> transform = trans , label = sll , <EOL> ** marker_props [ sl ] ) <EOL> if horizontal : <EOL> pos -= dpos <EOL> else : <EOL> pos += dpos <EOL> if horizontal : <EOL> ax . xaxis . set_ticks_position ( "<STR_LIT>" ) <EOL> ax . yaxis . set_ticks_position ( "<STR_LIT:none>" ) <EOL> ax . set_yticklabels ( [ ] ) <EOL> ax . spines [ '<STR_LIT:left>' ] . set_color ( '<STR_LIT:none>' ) <EOL> ax . spines [ '<STR_LIT:right>' ] . set_color ( '<STR_LIT:none>' ) <EOL> ax . spines [ '<STR_LIT>' ] . set_color ( '<STR_LIT:none>' ) <EOL> ax . spines [ '<STR_LIT>' ] . set_position ( ( '<STR_LIT>' , - <NUM_LIT:0.1> / aheight ) ) <EOL> ax . set_ylim ( <NUM_LIT:0> , <NUM_LIT:1> ) <EOL> ax . yaxis . set_ticks ( ticks ) <EOL> ax . autoscale_view ( scaley = False , tight = True ) <EOL> else : <EOL> ax . yaxis . set_ticks_position ( "<STR_LIT:left>" ) <EOL> ax . xaxis . set_ticks_position ( "<STR_LIT:none>" ) <EOL> ax . set_xticklabels ( [ ] ) <EOL> ax . spines [ '<STR_LIT>' ] . set_color ( '<STR_LIT:none>' ) <EOL> ax . spines [ '<STR_LIT:right>' ] . set_color ( '<STR_LIT:none>' ) <EOL> ax . spines [ '<STR_LIT>' ] . set_color ( '<STR_LIT:none>' ) <EOL> ax . spines [ '<STR_LIT:left>' ] . set_position ( ( '<STR_LIT>' , - <NUM_LIT:0.1> / awidth ) ) <EOL> ax . set_xlim ( <NUM_LIT:0> , <NUM_LIT:1> ) <EOL> ax . xaxis . set_ticks ( ticks ) <EOL> ax . autoscale_view ( scalex = False , tight = True ) <EOL> return fig </s>
