def gp_datdir(initial, topN):
<EOL>inDir, outDir = getWorkDirs()<EOL>initial = initial.capitalize()<EOL>inDir = os.path.join(inDir, initial)<EOL>if not os.path.exists(inDir): <EOL><INDENT>return "<STR_LIT>" % initial<EOL><DEDENT>data = OrderedDict()<EOL>for file in os.listdir(inDir):<EOL><INDENT>country = os.path.splitext(file)[<NUM_LIT:0>]<EOL>file_url = os.path.join(inDir, file)<EOL>data[country] = np.loadtxt(open(file_url, '<STR_LIT:rb>')) <EOL>data[country][:, <NUM_LIT:1>] /= <NUM_LIT><EOL>if data[country].shape[<NUM_LIT:1>] > <NUM_LIT:2>: data[country][:, <NUM_LIT:3>:] /= <NUM_LIT><EOL><DEDENT>logging.debug(data) <EOL>sorted_data = OrderedDict(sorted(<EOL>list(data.items()), key = lambda t: np.mean(t[<NUM_LIT:1>][:,<NUM_LIT:1>]), reverse = True<EOL>))<EOL>top_data = OrderedDict(<EOL>sorted_data.popitem(last = False) for i in range(topN)<EOL>if sorted_data<EOL>)<EOL>nSets = len(top_data)<EOL>make_plot(<EOL>data = list(top_data.values()),<EOL>properties = [ getOpts(i) for i in range(nSets) ],<EOL>titles = list(top_data.keys()), <EOL>name = os.path.join(outDir, initial),<EOL>key = [ '<STR_LIT>', '<STR_LIT>' ],<EOL>ylabel = '<STR_LIT>',<EOL>xlabel = '<STR_LIT>', rmargin = <NUM_LIT>, tmargin = <NUM_LIT>, size='<STR_LIT>'<EOL>)<EOL>return '<STR_LIT>'<EOL>
example for plotting from a text file via numpy.loadtxt

    1. prepare input/output directories
    2. load the data into an OrderedDict() [adjust axes units]
    3. sort countries from highest to lowest population
    4. select the <topN> most populated countries
    5. call ccsgp.make_plot with data from 4

    Below is an output image for country initial T and the 4 most populated
    countries for this initial (click to enlarge). Also see::

      $ python -m ccsgp_get_started.examples.gp_datdir -h

    for help on the command line options.

    .. image:: pics/T.png
       :width: 450 px

    .. image:: pics/U.png
       :width: 450 px

    :param initial: country initial
    :type initial: str
    :param topN: number of most populated countries to plot
    :type topN: int
    :ivar inDir: input directory according to package structure and initial
    :ivar outDir: output directory according to package structure
    :ivar data: OrderedDict with datasets to plot as separate keys
    :ivar file: data input file for specific country, format: [x y] OR [x y dx dy]
    :ivar country: country, filename stem of input file
    :ivar file_url: absolute url to input file
    :ivar nSets: number of datasets