Linear Label on Logarithmic Plot

18 views (last 30 days)
Hello!
I have an "example" regression loglog graph to show someone. The Y axis is not very large, but is less than 1, so it shows up as log rather than linear.
Is there a way to do this cleanly? Here's the code:
% reggie
rng('shuffle');
Intercept = 1000;
Slope = -1.6;
dist = 150:50:300;
vib = Intercept*(dist.^Slope);
minx = 50;
maxx = 400;
figure
loglog(dist,vib,'o','MarkerFaceColor','r')
xlim([minx maxx])
ylim([0.05 1])
hold on
grid on
grid minor
loglog([minx maxx],[Intercept*(minx^Slope) Intercept*(maxx^Slope)],'--');
xlabel('Distance (ft)');
ylabel('Vibration (in/s)');
title('Regression Example');
for n = 1:length(dist)
scatterling = 0.3 * vib(n);
median_value = vib(n);
new_values = scatterling.*randn(6,1)+median_value;
loglog(dist(n),new_values,'diamond','LineStyle','none');
end
newdist = 100;
reduction_factor = 0.65;
newvib = (reduction_factor * Intercept) *(newdist.^Slope);
loglog(newdist,newvib,'o','MarkerFaceColor','b');
scatterling = 0.4 * newvib;
median_value = newvib;
new_values = scatterling.*randn(6,1)+median_value;
loglog(newdist,new_values,'diamond','LineStyle','none','MarkerFaceColor','g');
Thanks!
Doug
  2 Comments
Walter Roberson
Walter Roberson on 13 May 2021
It is not clear what you are asking for??
You do loglog plots. If you do not want to reprogram that to linear, you could
set(gca, 'YScale', 'linear')
Douglas Anderson
Douglas Anderson on 14 May 2021
Thank you Walter.
I would like the scale to be logarithmic, but the label to be linear. For this case, it's basically from 0.05 to 1.0. So there wouldn't be a lot of points, but as it is, I get two labels: 10 superscript -1 and 10 superscript 0.
Thanks!
Doug

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 14 May 2021
ax = gca;
ax.YAxis.Exponent = 0;
  2 Comments
Douglas Anderson
Douglas Anderson on 14 May 2021
This made sense, but didn't work. Here's the results with that code added, both after the initial plot and at the end.
Tried also ax.YTick = [1 10], and that didn't work either.
Thank you, though! Any other thoughts?
Walter Roberson
Walter Roberson on 14 May 2021
Edited: Walter Roberson on 14 May 2021
% reggie
rng('shuffle');
Intercept = 1000;
Slope = -1.6;
dist = 150:50:300;
vib = Intercept*(dist.^Slope);
minx = 50;
maxx = 400;
figure
loglog(dist,vib,'o','MarkerFaceColor','r')
xlim([minx maxx])
ylim([0.05 1])
hold on
grid on
grid minor
loglog([minx maxx],[Intercept*(minx^Slope) Intercept*(maxx^Slope)],'--');
xlabel('Distance (ft)');
ylabel('Vibration (in/s)');
title('Regression Example');
for n = 1:length(dist)
scatterling = 0.3 * vib(n);
median_value = vib(n);
new_values = scatterling.*randn(6,1)+median_value;
loglog(dist(n),new_values,'diamond','LineStyle','none');
end
newdist = 100;
reduction_factor = 0.65;
newvib = (reduction_factor * Intercept) *(newdist.^Slope);
loglog(newdist,newvib,'o','MarkerFaceColor','b');
scatterling = 0.4 * newvib;
median_value = newvib;
new_values = scatterling.*randn(6,1)+median_value;
loglog(newdist,new_values,'diamond','LineStyle','none','MarkerFaceColor','g');
yticklabels(compose("%g", yticks))

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!