The ylabel gets half shown in the graph. Help me solving the problem, such that the ylabel is shown fully. Also, it would be better if the xlabel is moved near to the xtick. The code is written in Matlab. I would request to provide a solution in Matlab itself. Thanks in advance.
Below is the Matlab code:
clear;
% Change default axes fonts.
set(0,'DefaultAxesFontName', 'Times New Roman')
set(0,'DefaultAxesFontSize', 21)
% Change default text fonts.
set(0,'DefaultTextFontname', 'Times New Roman')
set(0,'DefaultTextFontSize', 21)
% Define data
x = [100, 200, 300, 400, 500];
data = [
5.3, 7.3, 4.3, 3.3, 1.3;
4.3, 4.3, 4.3, 5.3, 10.3;
2.3, 7.3, 2.3, 8.3, 2.3;
1.3, 9.3, 8.3, 7.3, 0.3;
9.3, 2.3, 0.3, 2.3, 0.3;
6.3, 7.3, 9.3, 6.3, 7.3;
];
datasetNames = {'A', 'B', 'C', 'D', 'E', 'F'};
% Create a 3D bar chart
figure;
bar3(data);
% Customize the axes
set(gca, 'XTickLabel', x, 'YTickLabel', datasetNames, 'FontSize', 21); % Set x-axis labels as number of tasks
% Align labels
xlh = xlabel('Task Count', 'FontSize', 21, 'FontName', 'Times New Roman', 'FontWeight', 'normal', 'Rotation', -30);
ylh = ylabel('Method', 'FontSize', 21, 'FontName', 'Times New Roman', 'FontWeight', 'normal', 'Rotation', 37);
zlh = zlabel('Fitness', 'FontSize', 21, 'FontName', 'Times New Roman', 'FontWeight', 'normal');
% Set Z-axis limits
zlim([0.31, max(data(:))]); % Start Z-axis at 0.0018
% Set view angle for better visualization
view(45, 30);
% Adjust figure size and layout
set(gcf, 'Units', 'normalized', 'Position', [0.2, 0.2, 0.6, 0.6]);
% Adjust paper size for saving
fig = gcf;
fig.PaperUnits = 'centimeters';
fig.PaperPosition = [0 0 14.4 12.4];
fig.PaperSize = [13.4 11.5]; % width & height of page
% Save the figure
print('FST_D_S2.pdf','-dpdf','-r1200');
Santanu Ghosh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1
The issue with ylabel
being cut off usually occurs due to the figure layout and tight boundaries. You can resolve this by adjusting the axes and fig properties. You can move the xlabel
closer to the xticks
by adjusting its position manually.
I believe this code here should solve your problems for showing ylabel
fully and moving the xlabel
closer to the xticks
:
clear;
% Change default axes fonts.
set(0,'DefaultAxesFontName', 'Times New Roman')
set(0,'DefaultAxesFontSize', 21)
% Change default text fonts.
set(0,'DefaultTextFontname', 'Times New Roman')
set(0,'DefaultTextFontSize', 21)
% Define data
x = [100, 200, 300, 400, 500];
data = [
5.3, 7.3, 4.3, 3.3, 1.3;
4.3, 4.3, 4.3, 5.3, 10.3;
2.3, 7.3, 2.3, 8.3, 2.3;
1.3, 9.3, 8.3, 7.3, 0.3;
9.3, 2.3, 0.3, 2.3, 0.3;
6.3, 7.3, 9.3, 6.3, 7.3;
];
datasetNames = {'A', 'B', 'C', 'D', 'E', 'F'};
% Create a 3D bar chart
figure;
bar3(data);
% Customize the axes
set(gca, 'XTickLabel', x, 'YTickLabel', datasetNames, 'FontSize', 21); % Set x-axis labels as number of tasks
% Align labels
xlh = xlabel('Task Count', 'FontSize', 21, 'FontName', 'Times New Roman', 'FontWeight', 'normal', 'Rotation', -30);
ylh = ylabel('Method', 'FontSize', 21, 'FontName', 'Times New Roman', 'FontWeight', 'normal', 'Rotation', 37);
zlh = zlabel('Fitness', 'FontSize', 21, 'FontName', 'Times New Roman', 'FontWeight', 'normal');
% Adjust position of the xlabel to bring it closer to xticks
xlh.Position(2) = xlh.Position(2) - 1; % Adjust the vertical position as needed
% Adjust axes properties to make ylabel fully visible
set(gca, 'Position', [0.2, 0.2, 0.6, 0.6]); % Modify axes position within the figure
outerpos = get(gca, 'OuterPosition'); % Get current outer position
ti = get(gca, 'TightInset'); % Get tight inset for padding
set(gca, 'Position', [outerpos(1) + ti(1), outerpos(2) + ti(2), ...
outerpos(3) - ti(1) - ti(3), outerpos(4) - ti(2) - ti(4)]); % Adjust for tight layout
% Set Z-axis limits
zlim([0.31, max(data(:))]); % Start Z-axis at 0.31
% Set view angle for better visualization
view(45, 30);
% Adjust figure size and layout
set(gcf, 'Units', 'normalized', 'Position', [0.2, 0.2, 0.6, 0.6]);
% Adjust paper size for saving
fig = gcf;
fig.PaperUnits = 'centimeters';
fig.PaperPosition = [0 0 14.4 12.4];
fig.PaperSize = [13.4 11.5]; % width & height of page
% Save the figure
print('FST_D_S2.pdf','-dpdf','-r1200');
I may have missed something. If so, I will edit the post.