docs: def show_plots(fitdata, fitval, x=None, save=False, view='ratio'):
          """ Show plots comparing ``fitdata[k],fitval[k]`` for each key ``k`` in ``fitval``.
  
          Assumes :mod:`matplotlib` is installed (to make the plots). Plots
          are shown for one correlator at a time. Press key ``n`` to see the
          next correlator; press key ``p`` to see the previous one; press key
          ``q`` to quit the plot and return control to the calling program;
          press a digit to go directly to one of the first ten plots. Zoom,
          pan and save using the window controls.
  
          There are several different views available for each plot,
          specified by parameter ``view``:
  
              ``view='ratio'``: Data divided by fit (default).
  
              ``view='diff'``: Data minus fit, divided by data's standard deviation.
  
              ``view='std'``: Data and fit.
  
              ``view='log'``: ``'std'`` with log scale on the vertical axis.
  
              ``view='loglog'``: `'std'`` with log scale on both axes.
  
          Press key ``v`` to cycle through these  views; or press keys
          ``r``, ``d``, or ``l`` for the ``'ratio'``, ``'diff'``,
          or ``'log'`` views, respectively.
  
          Copies of the plots that are viewed can be saved by setting parameter
          ``save=fmt`` where ``fmt`` is a string used to create
          file names: the file name for the plot corresponding to key
          ``k`` is ``fmt.format(k)``. It is important that the
          filename end with a suffix indicating the type of plot file
          desired: e.g., ``fmt='plot-{}.pdf'``.
          """
          import matplotlib.pyplot as plt
          # collect plotinfo
          plotinfo = collections.OrderedDict()
          for tag in fitval:
              d = fitdata[tag]
              f = fitval[tag]
              plotinfo[tag] = (
                  numpy.arange(len(d))+1 if x is None else x[tag],
                  gvar.mean(d), gvar.sdev(d),  gvar.mean(f), gvar.sdev(f)
                  )
          plotinfo_keys = list(plotinfo.keys())
          fig = plt.figure()
          viewlist = ['ratio', 'diff', 'std', 'log', 'loglog']
          def onpress(event):
              if event is not None:
                  try:    # digit?
                      onpress.idx = int(event.key)
                  except ValueError:
                      if event.key == 'n':
                          onpress.idx += 1
                      elif event.key == 'p':
                          onpress.idx -= 1
                      elif event.key == 'v':
                          onpress.view = (onpress.view + 1) % len(viewlist)
                      elif event.key == 'r':
                          onpress.view = viewlist.index('ratio')
                      elif event.key == 'd':
                          onpress.view = viewlist.index('diff')
                      elif event.key == 'l':
                          onpress.view = viewlist.index('log')
                      # elif event.key == 'q':  # unnecessary
                      #     plt.close()
                      #     return
                      else:
                          return
              else:
                  onpress.idx = 0
  
              # do the plot
              if onpress.idx >= len(plotinfo_keys):
                  onpress.idx = len(plotinfo_keys)-1
              elif onpress.idx < 0:
                  onpress.idx = 0
              i = onpress.idx
              k = plotinfo_keys[i]
              x, g, dg, gth, dgth = plotinfo[k]
              fig.clear()
              plt.title("%d) %s   (press 'n', 'p', 'q', 'v' or a digit)"
                          % (i, k))
              dx = (max(x) - min(x)) / 50.
              plt.xlim(min(x)-dx, max(x)+dx)
              plotview = viewlist[onpress.view]
              if plotview in ['std', 'log', 'loglog']:
                  if plotview in ['log', 'loglog']:
                      plt.yscale('log', nonposy='clip')
                  if plotview == 'loglog':
                      plt.xscale('log', nonposx='clip')
                  plt.ylabel(str(k) + '   [%s]' % plotview)
                  if len(x) > 0:
                      if len(x) > 1:
                          plt.plot(x, gth, 'r-')
                          plt.fill_between(
                              x, y2=gth + dgth, y1=gth - dgth,
                              color='r', alpha=0.075,
                              )
                      else:
                          extra_x = [x[0] * 0.5, x[0] * 1.5]
                          plt.plot(extra_x, 2 * [gth[0]], 'r-')
                          plt.fill_between(
                              extra_x, y2=2 * [gth[0] + dgth[0]],
                              y1=2 * [gth[0] - dgth[0]],
                              color='r', alpha=0.075,
                              )
                      plt.errorbar(x, g, dg, fmt='o')
              elif plotview == 'ratio':
                  plt.ylabel(str(k)+' / '+'fit'  + '   [%s]' % plotview)
                  ii = (gth != 0.0)       # check for exact zeros (eg, antiperiodic)
                  if len(x[ii]) > 0:
                      if len(x[ii]) > 1:
                          plt.fill_between(
                              x[ii], y2=1 + dgth[ii] / gth[ii],
                              y1=1 - dgth[ii] / gth[ii],
                              color='r', alpha=0.075,
                              )
                          plt.plot(x, numpy.ones(len(x), float), 'r-')
                      else:
                          extra_x = [x[ii][0] * 0.5, x[ii][0] * 1.5]
                          plt.fill_between(
                              extra_x, y2=2 * [1 + dgth[ii][0]/gth[ii][0]],
                              y1=2 * [1 - dgth[ii][0]/gth[ii][0]],
                              color='r', alpha=0.075,
                              )
                          plt.plot(extra_x, numpy.ones(2, float), 'r-')
                      plt.errorbar(x[ii], g[ii]/gth[ii], dg[ii]/gth[ii], fmt='o')
              elif plotview == 'diff':
                  plt.ylabel('({} - fit) / sigma'.format(str(k))  + '   [%s]' % plotview)
                  ii = (dg != 0.0)       # check for exact zeros
                  if len(x[ii]) > 0:
                      if len(x[ii]) > 1:
                          plt.fill_between(
                              x[ii], y2=dgth[ii] / dg[ii],
                              y1=-dgth[ii] / dg[ii],
                              color='r', alpha=0.075
                              )
                          plt.plot(x, numpy.zeros(len(x), float), 'r-')
                      else:
                          extra_x = [x[ii][0] * 0.5, x[ii][0] * 1.5]
                          plt.fill_between(
                              extra_x, y2=2 * [dgth[ii][0] / dg[ii][0]],
                              y1=2 * [-dgth[ii][0] / dg[ii][0]],
                              color='r', alpha=0.075
                              )
                          plt.plot(extra_x, numpy.zeros(2, float), 'r-')
                      plt.errorbar(
                          x[ii], (g[ii] - gth[ii]) / dg[ii], dg[ii] / dg[ii],
                          fmt='o'
                          )
              if save:
                  plt.savefig(save.format(k), bbox_inches='tight')
              else:
                  plt.draw()
          onpress.idx = 0
          try:
              onpress.view = viewlist.index(view)
          except ValueError:
              raise ValueError('unknow view: ' + str(view))
          fig.canvas.mpl_connect('key_press_event', onpress)
          onpress(None)
          plt.show()