def plot_image(f,
               img_path,
               cell_x0,
               cell_x1,
               cell_y0,
               ax,
               text_y_dist,
               text,
               text_pos,
               fontsize,
               zoom=0.2,
               cell_y1=np.nan):
    """ This function plots images and corresponding text of the task schematic

    :param f: Figure object
    :param img_path: Path of image
    :param cell_x0: Left x-position of area in which it is plotted centrally
    :param cell_x1: Rigth x-position of area in which it is plotted centrally
    :param cell_y0: Lower y-position of image -- if cell_y1 = nan
    :param ax: Plot axis
    :param text_y_dist: y-position distance to image
    :param text: Displayed text
    :param text_pos: Position of printed text (below vs. above)
    :param fontsize: Text font size
    :param zoom: Scale of image
    :param cell_y1: Upper x-position of area in which image is plotted (lower corresponds to cell_y0)
    :return ax, bbox: Axis object, image coordinates
    """

    # Open image
    img = Image.open(img_path)

    # Image zoom factor and axis and coordinates
    imagebox = OffsetImage(img, zoom=zoom)
    imagebox.image.axes = ax
    ab = AnnotationBbox(imagebox, (cell_x0, cell_y0),
                        xybox=None,
                        xycoords='data',
                        boxcoords="offset points",
                        pad=0,
                        frameon=False)
    ax.add_artist(ab)

    # Get cell width
    cell_width = cell_x1 - cell_x0
    image_x = cell_x0 + (cell_width / 2)

    if not np.isnan(cell_y1):
        cell_height = cell_y1 - cell_y0
        image_y = cell_y0 + (cell_height / 2)
    else:
        image_y = cell_y0

    # Remove image and re-plot at correct coordinates
    ab.remove()
    ab = AnnotationBbox(imagebox, (image_x, image_y),
                        xybox=None,
                        xycoords='data',
                        boxcoords="offset points",
                        pad=0,
                        frameon=False)
    ax.add_artist(ab)

    # Get image coordinates
    f.canvas.draw()
    renderer = f.canvas.renderer
    # bbox = imagebox.get_window_extent(renderer).inverse_transformed(ax.transAxes)
    bbox = imagebox.get_window_extent(renderer).inverse_transformed(
        ax.transData)

    if text_pos == 'left_below':
        # Plot text below image
        x = bbox.x0
        y = bbox.y0 - text_y_dist
    elif text_pos == 'centered_below':
        # Plot text centrally above image
        word_length, _, _ = get_text_coords(f, ax, bbox.x0, bbox.y0, text, 6)
        cell_width = bbox.x1 - bbox.x0
        x = center_x(bbox.x0, cell_width, word_length)
        y = bbox.y0 - text_y_dist
    else:
        # Plot text centrally above image
        word_length, _, _ = get_text_coords(f, ax, bbox.x0, bbox.y0, text, 6)
        cell_width = bbox.x1 - bbox.x0
        x = center_x(bbox.x0, cell_width, word_length, correct_for_length=True)
        y = bbox.y1 + text_y_dist

    ax.text(x, y, text, fontsize=fontsize, color='k')

    return ax, bbox