Problem with plotting on log scale - disappearing line on plot...

19 次查看(过去 30 天)
Hi all,
So I'm working on plotting data for x-y comparisons, along with outliers that have been removed, and a custom-generated trend line, and with the data color coded by sample concentration. This works in the below code:
f2 = figure('visible','on');
hold on
scatter(xout, yout, 25, fcolor,'filled');
hold on
scatter(outlier(:,1),outlier(:,2),25,'k','filled');
hold on
plot(xplot,yplot,'LineWidth',2);
hold on
%set(gca,'xscale','log','yscale','log')
title('Insitu v. Flask Mixing Ratio, Logarithmic');
legend('Flask vs Insitu (ppbv)', 'Outliers', 'Orthogonal Regression Line');
xlabel('Flask (ppbv)')
ylabel('Insitu (ppbv)')
hold off
saveas(f2,'test1','jpeg')
But, it fails when I un-comment line that's setting the scales as logarithmic. The data still plots, and does show the bias I'm looking for, but the regression line disappears. I've tried just about every ordered variation of hold on, off, etc and changed the order things are plotted in etc...I'm stuck.
Any suggestions for tinkering, or is this a legitimate issue with the code and or something I'm missing?
Thanks, Brendan

采纳的回答

Mike Garrity
Mike Garrity 2016-4-20
I'm guessing that xplot and yplot are 2 element vectors where one of the values is 0. In that case, one of the 2 points on the line transforms to NaN when the log is calculated, so no line is drawn.
If this is the case, probably the simplest would be to add more vertices to the line using something like this:
t = linspace(0,1,100);
xplot = xplot(1) + t*(xplot(end) - xplot(1));
yplot = yplot(1) + t*(yplot(end) - yplot(1));
  1 个评论
Brendan Blanchard
Brendan Blanchard 2016-4-20
Thanks Mike! This was the issue and I was able to re-assign xplot and yplot to just barely positive numbers by catching this before plotting.
Cheers!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Histograms 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by