y-axis with diffent scalings
7 ビュー (過去 30 日間)
古いコメントを表示
Hello,
in the attached figure I'd like to make the y values between 0 and 0.05 (dashed line) appear more clearly visible, as a lot of values are located in this range. Basically, I'd like the y axis to be scaled between 0 and 0.05 in steps of 0.01 and the scaling of all values > 0.05 should be like in the attached figure. How can I do this?
0 件のコメント
回答 (2 件)
chicken vector
2023 年 6 月 4 日
If you want to keep the figure with this format, I'd say you have two options.
You can either make an axis break with the FEX functions mentioned here:
Or you change the scale of Y-axis to the only non-linear option avilable:
x = repmat(1 : .5 : 6, 1, 4);
data = rand(size(x)) * 10;
idx = data > 5;
data(idx) = .5 + rand(size(find(idx))) / 3;
figure;
tiledlayout(2, 1);
nexttile;
scatter(x, data);
nexttile;
scatter(x, data);
set(gca, 'YScale', 'Log');
0 件のコメント
Simon Chan
2023 年 6 月 4 日
Separate the data into two groups and plot the larger and smaller values using left and right y-axis respectively.
Adjust the y-axis scale on both sides and finally hide the right y-axis.
Agree that it is a bit complicated but final result is similar to what you need.
x = 1:0.5:6;
y = [rand(4,numel(x))*0.05; rand(4,numel(x))];
threshold = 0.05;
idx = y>threshold;
ylarge = y.*idx;
ylarge(~idx) = NaN;
ysmall = y.*~idx;
ysmall(idx) = NaN;
% 5 steps from 0 to 0.05 & 19 steps from 0.05 to 1.0
nLevel_large = (1.0-threshold)/threshold;
nLevel_small = (threshold-0)/0.01;
nLevel = nLevel_large + nLevel_small;
ystart_large = 1 - nLevel*threshold;
yend_small = 0.01*nLevel;
f = figure;
ax1= axes(f);
yyaxis(ax1,'left')
yline(ax1,threshold,'-.')
marker = ["s","*","o","d","s","*","o","d"];
color = ["r","b","g","m","m","g","b","r"];
arrayfun(@(r) line(x,ylarge(r,:),'LineStyle','none','Marker',marker(r),'Color',color(r)),1:8,'uni',0);
ax1.YLim = [ystart_large 1];
ax1.YTick= ystart_large:threshold:1.0;
ax1.YTickLabel = [compose('%.2f',0:0.01:0.04),compose('%.2f',threshold:threshold:1.00)];
yyaxis(ax1,'right');
arrayfun(@(r) line(x,ysmall(r,:),'LineStyle','none','Marker',marker(r),'Color',color(r)),1:8,'uni',0);
ax1.YLim = [0 yend_small];
ax1.YAxis(2).Visible='off';
grid(ax1,'on');
参考
カテゴリ
Help Center および File Exchange で Specifying Target for Graphics Output についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!