<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def plot_porosity_profile(self, fig=None):
 r""" Return a porosity profile in all orthogonal directions by summing the voxel volumes in consectutive slices. """

        if hasattr(self, '_fiber_image') is False:
            logger.warning('This method only works when a fiber image exists')
            return

        l = sp.asarray(sp.shape(self._fiber_image))
        px = sp.zeros(l[0])
        py = sp.zeros(l[1])
        pz = sp.zeros(l[2])

        for x in sp.arange(l[0]):
            px[x] = sp.sum(self._fiber_image[x, :, :])
            px[x] /= sp.size(self._fiber_image[x, :, :])
        for y in sp.arange(l[1]):
            py[y] = sp.sum(self._fiber_image[:, y, :])
            py[y] /= sp.size(self._fiber_image[:, y, :])
        for z in sp.arange(l[2]):
            pz[z] = sp.sum(self._fiber_image[:, :, z])
            pz[z] /= sp.size(self._fiber_image[:, :, z])

        if fig is None:
            fig = plt.figure()
        ax = fig.gca()
        plots = []
        plots.append(plt.plot(sp.arange(l[0])/l[0], px, 'r', label='x'))
        plots.append(plt.plot(sp.arange(l[1])/l[1], py, 'g', label='y'))
        plots.append(plt.plot(sp.arange(l[2])/l[2], pz, 'b', label='z'))
        plt.xlabel('Normalized Distance')
        plt.ylabel('Porosity')
        handles, labels = ax.get_legend_handles_labels()
        ax.legend(handles, labels, loc=1)
        plt.legend(bbox_to_anchor=(1, 1), loc=2, borderaxespad=0.)
        return fig