X and Y axis labels overwritten and illiegible

5 ビュー (過去 30 日間)
John Micco
John Micco 2018 年 6 月 25 日
コメント済み: Ameer Hamza 2018 年 6 月 26 日
I wrote the following code to put both the X and Y axis on log scale and do a scatter plot:
% Create figure
fig = figure;
title(['Test target transitions for ', date]);
set(fig, 'PaperOrientation', 'landscape')
xlabel('Number of Samples')
ylabel('Ratio of transitions / Number of Samples')
% Create axes
axes1 = axes('Parent',fig);
xtickformat('%10.4f');
ytickformat('%10.4f');
% Set the remaining axes properties
set(axes1,...
'XMinorTick','off',...
'XScale','log',...
'YMinorTick','off',...
'YScale','log');
% Create scatter
sflaky= scatter(X1,Y1);
hold(axes1,'on');
% Create scatter
snotflaky = scatter(X1,Y2);
p95Line = plot(points95(:,2), points95(:,1));
set(p95Line , 'LineWidth', 4);
p99Line = plot(points99(:,2), points99(:,1));
set(p99Line, 'LineWidth', 4);
p999Line = plot(points999(:,2), points999(:,1));
set(p999Line, 'LineWidth', 4);
legend([sflaky, snotflaky, p95Line, p99Line, p999Line], ...
{'flaky', 'not flaky', '95% pFlaky', '99% pFlaky', '99.9% pFlaky'});
When I run the code, I get garbled X and Y tick labels and I am not sure why. Reproduced both online and in my local version of MATLAB.
See the attached PDF file for an example of what it looks like.

回答 (2 件)

Ameer Hamza
Ameer Hamza 2018 年 6 月 25 日
I don't have your data, therefore, can't test the complete code but I guess the problem is happening because your code is effectively creating 2 axes objects, which overlaps and creating illegible text. Try changing the order of lines at the beginning of your code as follow
fig = figure;
% Create axes
axes1 = axes('Parent',fig);
title(['Test target transitions for ', date]);
set(fig, 'PaperOrientation', 'landscape')
xlabel('Number of Samples')
ylabel('Ratio of transitions / Number of Samples')
xtickformat('%10.4f'); ytickformat('%10.4f');
% Set the remaining axes properties
set(axes1,...
'XMinorTick','off',...
'XScale','log',...
'YMinorTick','off',...
'YScale','log');

John Micco
John Micco 2018 年 6 月 25 日
Thanks so much for your timely answer! It was very helpful and the multiple axes problem was not something that occurred to me!
I ended up with:
% Create figure
fig = figure;
axes1 = gca;
hold(axes1,'on');
title(['Test target transitions for ', date]);
set(fig, 'PaperOrientation', 'landscape')
xlabel('Number of Samples')
ylabel('Ratio of transitions / Number of Samples')
xtickformat('%10.4f');
ytickformat('%10.4f');
% Set the remaining axes properties
set(axes1,...
'XScale','log',...
'YScale','log');
% Create scatter
sflaky= scatter(X1,Y1);
% Create scatter
snotflaky = scatter(X1,Y2);
p95Line = plot(points95(:,2), points95(:,1));
set(p95Line , 'LineWidth', 4);
p99Line = plot(points99(:,2), points99(:,1));
set(p99Line, 'LineWidth', 4);
p999Line = plot(points999(:,2), points999(:,1));
set(p999Line, 'LineWidth', 4);
legend([sflaky, snotflaky, p95Line, p99Line, p999Line], ...
{'flaky', 'not flaky', '95% pFlaky', '99% pFlaky', '99.9% pFlaky'});
The only remaining question is how do I get the Axes labels to come out as floating point and not exponentials? I have seen some answers but all involve re-parsing the labels put on by "Log" view.
See the attached PDF.
  3 件のコメント
John Micco
John Micco 2018 年 6 月 26 日
This answer gives up on the auto scaling and would not work if I use a set with different ranges. It seems like I ought to be able to control the generation of the XTick labels using the label format - could that be a bug?
Ameer Hamza
Ameer Hamza 2018 年 6 月 26 日
I am not sure whether it is a bug. It might be an intended behavior because it is more convenient to display and read values in the exponential form in log scale. Although it would be nice if MATLAB still provide control over label format even in log scale.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeAxis Labels についてさらに検索

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by