The problem is happening because you are viewing 3D plot from a 2D projection. In order to bring the line to the front, you need to give them z values greater the then the scatter plot points. You can use the following code to get the desired results
XLSdatafile = 'b46.csv';
XLIM = [0.4 0.24 ]; % beginning/end of yellow selection region
YLIM = [0.12 0.4 ]; % beginning/end of yellow selection region
INITIAL_FIT_GUESS = 0.0200; % initial ecd guess
INITIAL_2FIT_GUESS = 2.35 * INITIAL_FIT_GUESS;
if ~exist('XLSdatafile_loaded','var') || ~strcmp(XLSdatafile, XLSdatafile_loaded)
M = load(XLSdatafile);
XLSdatafile_loaded = XLSdatafile;
X = M(:,1);
Y = M(:,2);
end
f3=figure;
bins=75;
xi = linspace(min(X(:)),max(X(:)),bins);
yi = linspace(min(Y(:)),max(Y(:)),bins);
xr = interp1(xi,1:numel(xi),X,'nearest')';
yr = interp1(yi,1:numel(yi),Y,'nearest')';
scatter2dheat = log10(accumarray([xr' yr'], 1, [bins bins]));
scatter2dheat(isinf(scatter2dheat))=0; % replace inf with 0
pp3 = surf(xi,yi,scatter2dheat');
set(gca,'Clim',[max(min(scatter2dheat(:)),1e-3) max(scatter2dheat(:))]);
view(2)
grid off
shading flat
axis([min(X) max(X) min(Y) max(Y)]);
hold on
fit_const = INITIAL_FIT_GUESS;
time = 0.01:0.001:0.3;
current = fit_const./time;
figure(f3)
hold on
p_fit1 = plot3(time,current, max(max(scatter2dheat))*ones(size(time)),'r-', 'LineWidth', 4);
hold on
fit_const = INITIAL_2FIT_GUESS;
time = 0.01:0.001:0.5;
current = fit_const./time;
figure(f3)
hold on
p_fit2 = plot3(time,current, max(max(scatter2dheat))*ones(size(time)), 'r-','LineWidth', 4);
I have removed the colormap to keep code compact. You can add a color map of your choice.