import pkg_resources
import json


def createPlot(rows=1, cols=1, height=5, width=5, tight=True, suptitle=None):
    """
    Creates a new plot descriptor

    Parameters
    ----------
    rows: number of rows
    cols: number of columns
    height: height in centimeters
    width: width in centimeters
    tight: whether or not the plot layout is tight
    suptitle : string. Figure super title in the top part of the plot. Defaults to None.

    Returns
    -------
    map structure with the descriptor of the plot
    """
    try:
        fp = open(
            pkg_resources.resource_filename('pltutil.rsc', 'plot.json'))
        desc = json.load(fp)
        desc['width'] = width
        desc['height'] = height
        desc['rows'] = rows
        desc['columns'] = cols
        desc['tight'] = tight
        desc['suptitle'] = suptitle
        return desc
    except IOError:
        raise IOError('error reading json plot file')
    except ValueError:
        raise ValueError('malformed JSON text')