def draw_text(axis, text, i, j, to_tikz=False, **params):
    """
    Draws `text` on `axis` as position `(i, j)`.
    If `to_tikz`, axis is a list of tikz commands, else it's a matplotlib axis.
    `params` get passed to matplotlib.
    """
    if to_tikz:
        options = '[scale={}] '.format(params['fontsize']
            ) if 'fontsize' in params and params['fontsize'
            ] is not None else ''
        axis.append('\\node {}() at ({}, {}) {{{}}};\n'.format(options, i,
            j, text))
    else:
        params['fontsize'] = params.get('fontsize', None) or 12
        axis.text(i, j, text, **params)
