import six


def set_show(plotdata):
#------------------------------------------------------------------
    """
    Determine which figures and axes should be shown.
    plotaxes._show should be true only if plotaxes.show and at least one
    item is showing or if the axes have attribute type=='empty', in which
    case something may be plotting in an afteraxes command, for example.

    plotfigure._show should be true only if plotfigure.show and at least
    one axes is showing.
    """

    for figname in plotdata._fignames:
        plotfigure = plotdata.plotfigure_dict[figname]
        plotfigure._show = False
        if plotfigure.show:
            # Loop through all axes to make sure at least some item is showing
            for plotaxes in six.itervalues(plotfigure.plotaxes_dict):
                plotaxes._show = False
                if plotaxes.show:
                    # Loop through plotitems checking each item to see if it
                    # should be shown
                    for plotitem in six.itervalues(plotaxes.plotitem_dict):
                        plotitem._show = plotitem.show
                        if plotitem.show:
                            plotaxes._show = True
                            plotfigure._show = True
                    # Check to see if the axes are supposed to be empty or
                    # something may be in the afteraxes function
                    if not plotaxes._show:
                        if plotaxes.afteraxes is not None or plotaxes.type == 'empty':
                            plotaxes._show = True
                            plotfigure._show = True

    return plotdata