How can I make sure that cbarf (colorbar) will not overlap on second y-axis label?
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Ankitkumar Patel
am 17 Jul. 2023
Bearbeitet: Voss
am 18 Jul. 2023
% Create a data sets
data = rescale(peaks,0,600);
data1 = rescale(peaks,0,700);
newTickVals = [3 25 300 350 450];
limits=[newTickVals(1) newTickVals(end)];
x=1:1:49;z=ones(size(x));
f1=figure('Position', [0 400 1500 500]);
t1=tiledlayout(1,2);
% Tile 1
nexttile
contourf(data,newTickVals,"ShowText","on")
C=colormap('parula');
colormap(flipud(C))
clim(limits)
colororder({'r'})
yyaxis right
plot(x,z,'red',LineWidth=2)
ylabel('\bf Z values','Color','r','FontSize',18)
% Tile 2
nexttile
contourf(data1,newTickVals,"ShowText","on")
C1=colormap('parula');
colormap(flipud(C1))
h2=cbarf(data1,newTickVals);
cbarf;
clim(limits)
cbarf;
colororder({'r'})
yyaxis right
plot(x,z,'red',LineWidth=2)
ylabel('\bf Z values','Color','r','FontSize',18)
How can I make sure that cbarf (colorbar) will not overlap on second y-axis label?
0 Kommentare
Akzeptierte Antwort
Voss
am 18 Jul. 2023
Bearbeitet: Voss
am 18 Jul. 2023
Like the warning says, you cannot manually set the position of something controlled by a TiledChartLayout.
However, you can avoid using tiledlayout and instead create the axes explicitly and then move them and the colorbar wherever you want.
For example:
% Create a data sets
data = rescale(peaks,0,600);
data1 = rescale(peaks,0,700);
newTickVals = [3 25 300 350 450];
limits=[newTickVals(1) newTickVals(end)];
x=1:1:49;z=ones(size(x));
f1=figure('Position', [0 400 1500 500]);
% Tile 1
axes( ...
'Parent',f1, ...
'Units','normalized', ...
'Position',[0.05 0.05 0.35 0.9]);
contourf(data,newTickVals,"ShowText","on")
C=colormap('parula');
colormap(flipud(C))
clim(limits)
colororder({'r'})
yyaxis right
plot(x,z,'red',LineWidth=2)
ylabel('\bf Z values','Color','r','FontSize',18)
% Tile 2
axes( ...
'Parent',f1, ...
'Units','normalized', ...
'Position',[0.5 0.05 0.38 0.9]) % width after adding cbarf becomes 0.35
contourf(data1,newTickVals,"ShowText","on")
C1=colormap('parula');
colormap(flipud(C1))
h2=cbarf(data1,newTickVals);
set(h2,'Position',[0.9 0.1 0.02 0.8])
clim(limits)
colororder({'r'})
yyaxis right
plot(x,z,'red',LineWidth=2)
ylabel('\bf Z values','Color','r','FontSize',18)
2 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Colormaps finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!