Need to make the axis on the yyaxis and top of the graph

2 visualizaciones (últimos 30 días)
Viswajit Talluru
Viswajit Talluru el 29 de Ag. de 2024
Comentada: Viswajit Talluru el 3 de Sept. de 2024
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;

Respuestas (1)

Sahas
Sahas el 30 de Ag. de 2024
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 comentarios
Sahas
Sahas el 2 de Sept. de 2024
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!

Iniciar sesión para comentar.

Categorías

Más información sobre Discrete Data Plots en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by