def plot_linear_relation(x, y, x_err=None, y_err=None, title=None, point_label=None, legend=None, plot_range=None, plot_range_y=None, x_label=None, y_label=None, y_2_label=None, log_x=False, log_y=False, size=None, filename=None):
fig = Figure()<EOL>FigureCanvas(fig)<EOL>ax = fig.add_subplot(<NUM_LIT>)<EOL>if x_err is not None:<EOL><INDENT>x_err = [x_err, x_err]<EOL><DEDENT>if y_err is not None:<EOL><INDENT>y_err = [y_err, y_err]<EOL><DEDENT>ax.set_title(title)<EOL>if y_label is not None:<EOL><INDENT>ax.set_ylabel(y_label)<EOL><DEDENT>if log_x:<EOL><INDENT>ax.set_xscale('<STR_LIT>')<EOL><DEDENT>if log_y:<EOL><INDENT>ax.set_yscale('<STR_LIT>')<EOL><DEDENT>if plot_range:<EOL><INDENT>ax.set_xlim((min(plot_range), max(plot_range)))<EOL><DEDENT>if plot_range_y:<EOL><INDENT>ax.set_ylim((min(plot_range_y), max(plot_range_y)))<EOL><DEDENT>if legend:<EOL><INDENT>fig.legend(legend, <NUM_LIT:0>)<EOL><DEDENT>ax.grid(True)<EOL>ax.errorbar(x, y, xerr=x_err, yerr=y_err, fmt='<STR_LIT:o>', color='<STR_LIT>')  <EOL>if point_label is not None:<EOL><INDENT>for X, Y, Z in zip(x, y, point_label):<EOL><INDENT>ax.annotate('<STR_LIT:{}>'.format(Z), xy=(X, Y), xytext=(-<NUM_LIT:5>, <NUM_LIT:5>), ha='<STR_LIT:right>', textcoords='<STR_LIT>')<EOL><DEDENT><DEDENT>line_fit, _ = np.polyfit(x, y, <NUM_LIT:1>, full=False, cov=True)<EOL>fit_fn = np.poly1d(line_fit)<EOL>ax.plot(x, fit_fn(x), '<STR_LIT:->', lw=<NUM_LIT:2>, color='<STR_LIT>')<EOL>setp(ax.get_xticklabels(), visible=False)  <EOL>divider = make_axes_locatable(ax)<EOL>ax_bottom_plot = divider.append_axes("<STR_LIT>", <NUM_LIT>, pad=<NUM_LIT:0.0>, sharex=ax)<EOL>ax_bottom_plot.bar(x, y - fit_fn(x), align='<STR_LIT>', width=np.amin(np.diff(x)) / <NUM_LIT:2>, color='<STR_LIT>')<EOL><INDENT>plot(x, y - fit_fn(x))<EOL><DEDENT>ax_bottom_plot.grid(True)<EOL>if x_label is not None:<EOL><INDENT>ax.set_xlabel(x_label)<EOL><DEDENT>if y_2_label is not None:<EOL><INDENT>ax.set_ylabel(y_2_label)<EOL><DEDENT>ax.set_ylim((-np.amax(np.abs(y - fit_fn(x)))), (np.amax(np.abs(y - fit_fn(x)))))<EOL>ax.plot(ax.set_xlim(), [<NUM_LIT:0>, <NUM_LIT:0>], '<STR_LIT:->', color='<STR_LIT>')<EOL>setp(ax_bottom_plot.get_yticklabels()[-<NUM_LIT:2>:-<NUM_LIT:1>], visible=False)<EOL>if size is not None:<EOL><INDENT>fig.set_size_inches(size)<EOL><DEDENT>if not filename:<EOL><INDENT>fig.show()<EOL><DEDENT>elif isinstance(filename, PdfPages):<EOL><INDENT>filename.savefig(fig)<EOL><DEDENT>elif filename:<EOL><INDENT>fig.savefig(filename, bbox_inches='<STR_LIT>')<EOL><DEDENT>return fig<EOL>
Takes point data (x,y) with errors(x,y) and fits a straight line. The deviation to this line is also plotted, showing the offset.

     Parameters
    ----------
    x, y, x_err, y_err: iterable

    filename: string, PdfPages object or None
        PdfPages file object: plot is appended to the pdf
        string: new plot file with the given filename is created
        None: the plot is printed to screen