Need to make the axis on the yyaxis and top of the graph
조회 수: 3 (최근 30일)
이전 댓글 표시
a={'CNT 1% PDMS';'CNT 2% PDMS';'AP-CNT 1%';'AP-CNT 2%';'AP-AL-CNT 1%';'AP-AL-CNT 2%'};
y=[38.0498 44.8661 311.5 1.0225 61.5509 3.1161];
error=[16.1354 5.5303 82.2008 0.1427 27.6864 0.8204];
hold on
axis('padded')
numBars = numel(y);
x = 1:numBars;
sz = 200;
scatter(x,y,sz,'filled','square')
errorbar(x, y, error, '.','LineWidth',4,'Color','k')
grid on
set(gca,'yscale','log','XTick', 1:length(a),'XTickLabel',a);
%title('Base resistance', 'FontSize', 25, 'FontWeight', 'bold')
ylabel('Resistance in kΩ','FontSize', 25, 'FontWeight', 'bold')
ax = gca;
ax.XAxis.LineWidth = 5;
ax.XAxis.Color = 'k';
ax.FontSize = 25;
ax.YAxis.LineWidth = 5;
ax.YAxis.Color = 'k';
ax.FontSize = 25;
댓글 수: 0
답변 (1개)
Sahas
2024년 8월 30일
As per my understanding, you would like to add another y-axis in the plot and move the x-axis on the top.
Here's a revised version of the code snippet that uses MATLAB’s “yyaxis” function to create another y-axis on the right side.
a = {'CNT 1% PDMS'; 'CNT 2% PDMS'; 'AP-CNT 1%'; 'AP-CNT 2%'; 'AP-AL-CNT 1%'; 'AP-AL-CNT 2%'};
y = [38.0498 44.8661 311.5 1.0225 61.5509 3.1161];
error = [16.1354 5.5303 82.2008 0.1427 27.6864 0.8204];
figure;
hold on
axis('padded')
numBars = numel(y);
x = 1:numBars;
sz = 200;
%%%%% Use yyaxis for plotting another y-axis %%%%%
% Create the left y-axis
yyaxis left
scatter(x, y, sz, 'filled', 'square')
errorbar(x, y, error, '.', 'LineWidth', 4, 'Color', 'k')
ylabel('Resistance in kΩ', 'FontSize', 25, 'FontWeight', 'bold')
set(gca, 'yscale', 'log')
% If you have data for the right y-axis, you can enter it here
% yyaxis right
% plot(x, <data>, 'o-')
% ylabel(<label>)
set(gca, 'XTick', 1:length(a), 'XTickLabel', a, 'XAxisLocation', 'top');
ax = gca;
ax.XAxis.LineWidth = 5;
ax.XAxis.Color = 'k';
ax.FontSize = 10; %reduced the font for better view
ax.YAxis(1).LineWidth = 5;
ax.YAxis(1).Color = 'k';
% Customize if using the right y-axis
% ax.YAxis(2).LineWidth = 5;
% ax.YAxis(2).Color = 'k';
grid on
Refer to the below MathWorks documentation link on “yyaxis” for more information:
Hope this is beneficial!
댓글 수: 3
Sahas
2024년 9월 2일
You can use MATLAB's "box" function to display axes outlines. Refer to the following MATLAB documentation for ways to modify the properties of the box: https://www.mathworks.com/help/matlab/ref/box.html
Here's a version of the code snippet that uses MATLAB’s “box” function to create a black boundary around the plot:
a = {'CNT 1% PDMS'; 'CNT 2% PDMS'; 'AP-CNT 1%'; 'AP-CNT 2%'; 'AP-AL-CNT 1%'; 'AP-AL-CNT 2%'};
y = [38.0498 44.8661 311.5 1.0225 61.5509 3.1161];
error = [16.1354 5.5303 82.2008 0.1427 27.6864 0.8204];
hold on
axis('padded')
numBars = numel(y);
x = 1:numBars;
sz = 200;
scatter(x, y, sz, 'filled', 'square')
errorbar(x, y, error, '.', 'LineWidth', 4, 'Color', 'k')
% To get a black boundary box around the plot
box on
grid on
set(gca, 'yscale', 'log', 'XTick', 1:length(a), 'XTickLabel', a);
% title('Base resistance', 'FontSize', 25, 'FontWeight', 'bold')
ylabel('Resistance in kΩ', 'FontSize', 25, 'FontWeight', 'bold')
ax = gca;
ax.XAxis.LineWidth = 5;
ax.XAxis.Color = 'k';
ax.FontSize = 10; % Reduced font for better view
ax.YAxis.LineWidth = 5;
ax.YAxis.Color = 'k';
ax.FontSize = 10; % Reduced font for better view
Hope this helps you with your task!
참고 항목
카테고리
Help Center 및 File Exchange에서 Discrete Data Plots에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!