I am trying to use plotyy to specify the axes on a graph but I am struggling to figure out how to use it
1 次查看(过去 30 天)
显示 更早的评论
I am plotting a graph that uses semilog and plot and I want to specify the left and right axes as they use different units.
%% Set up the Import Options and import the data
opts = spreadsheetImportOptions("NumVariables", 5);
% Specify sheet and range
opts.Sheet = "Sheet1";
opts.DataRange = "Z1:AD202";
% Specify column names and types
opts.VariableNames = ["PressureMpa", "PoreDiameternm", "CumulativePoreVolumemLg", "SmoothedDVdlogDPoreVolumemLg", "OfTotalIntrusionVolume"];
opts.VariableTypes = ["double", "double", "double", "double", "double"];
% Import the data
mean = readtable("mean.xlsx", opts, "UseExcel", false);
%% Clear temporary variables
clear opts
figure
% Create axes
axes1 = axes('Parent',figure);
hold(axes1,'on');
semilogx(mean.PoreDiameternm(1:92),mean.SmoothedDVdlogDPoreVolumemLg(1:92),'DisplayName','Pore Size Distribution')
semilogx(mean.PoreDiameternm(1:92),mean.OfTotalIntrusionVolume(1:92),'LineStyle','-','Color','r','DisplayName','% Of Total Intrusion Volume');
% Activate the right side of the axes
yyaxis(axes1,'right');
set(axes1,'YColor',[0 0 0]);
% Uncomment the following line to preserve the Y-limits of the axes
% ylim(axes1,[0 0.2]);
ylabel('Smoothed dV/dlogD Pore Volume (mL/g)','Interpreter','latex')
yyaxis(axes1,'left');
% Uncomment the following line to preserve the Y-limits of the axes
% ylim(axes1,[0 0.2]);
ylabel('% Of Total Intrusion Volume','Interpreter','latex')
xlabel('Pore Diameter nm','Interpreter','latex')
hold(axes1,'off');
% Set the remaining axes properties
set(axes1,'XDir','reverse','XMinorTick','on','XScale','log');
Any help would be greatly aprreciated
edit, made it % of total volume as opposed to cumulative volume so my problem makes a little more sense
and I reuploaded my data
4 个评论
Les Beckham
2025-2-28
编辑:Les Beckham
2025-2-28
Unless you provide valid data (non-NaN), you are going to have a hard time getting help with plotting it. Did you read all of my comments? Your updated code has not addressed all of those issues.
采纳的回答
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Title 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!