Intersection of yline and x,y categorical data
4 views (last 30 days)
Show older comments
Alistair McQueen
on 29 Oct 2021
Commented: Star Strider
on 29 Oct 2021
I will not show the code which produces the data in the attached figure as I feel it is rendundant with my current issue.
In the figure attached, I have a series of points for which I have joined them by a line.
I also have a yline (50%) at which passes the previous plot line, once, around -7.5M. However, I want to have an exact value for this and to make the process automatic, rather than manual.
I have tried using various functions like interX and so on from file exchange but to no avail.
The data, and current plotting code is below:
Note - I did remove the first point of the data (ND) and then converted the xdata into numerical data, on the log scale but still had issues. Obviously, I removed the associated point from the yData vector.
I understand that this is probably the better way to do it, and then just plot the categorical case on top of the numerical case, like my code does.
% the original categorical x data
xS=categorical(["CTR" "-12" "-11" "-10" "-9" "-8" "-7"]);
xS = reordercats(xS,{'CTR' '-12' '-11' '-10' '-9' '-8' '-7'});
%Numerical version of above, removing the CTR entry (re-added back later)
cd = [1e-12 1e-11 1e-10 1e-9 1e-8 1e-7];
xS2 = log10(cd);
%The two different y data sets for each x data above
yS = [1 0.9995 0.9978 0.9815 0.8571 0.5576 0.4465]*100;
yS2 = [0.9995 0.9978 0.9815 0.8571 0.5576 0.4465]*100;
fig = figure(2);
%Actual plots
plot(xS,yS, '-o','Color','[0, 0.4470, 0.7410]',...
'LineWidth',3.5,'MarkerSize',20,...
'MarkerFaceColor','[0, 0.4470, 0.7410]','MarkerEdgeColor','k',...
'Linewidth',3);
hold on
yline(50, 'r--','Linewidth',3.5);
% Second to calc Ic50 value - uses numeric data
plot(xS2,yS2, '-o','Color','[0, 0.4470, 0.7410]',...
'LineWidth',3.5,'MarkerSize',20,...
'MarkerFaceColor','[0, 0.4470, 0.7410]','MarkerEdgeColor','k',...
'Linewidth',3);
xlabel('Dose [logM]'), ylabel('% Control')
leg = legend({'Cell Number','IC_5_0'});
leg.LineWidth=2.5;
leg.FontSize=28;
leg.NumColumns=1;
leg.LineWidth=2;
% Other plot stuff
box on
ax = gca;
set(gca,'linewidth', 2.5,'fontsize',28,'fontname','Helectiva') % Sets the width of the axis lines, font size, font
set(gca,'TickDir','out')
x0 = 50;
y0 = 50;
width=800;
height=600;
set(gcf,'position',[x0,y0,width,height])
0 Comments
Accepted Answer
Star Strider
on 29 Oct 2021
Since the ‘y’ values are monotonically decreasing, using interp1 is straightforward with the second vector, however there is no way to work with the categorical variables to interpolate them, so I just went with the indices instead.—
% the original categorical x data
xS=categorical(["CTR" "-12" "-11" "-10" "-9" "-8" "-7"]);
xS = reordercats(xS,{'CTR' '-12' '-11' '-10' '-9' '-8' '-7'});
%Numerical version of above, removing the CTR entry (re-added back later)
cd = [1e-12 1e-11 1e-10 1e-9 1e-8 1e-7];
xS2 = log10(cd);
%The two different y data sets for each x data above
yS = [1 0.9995 0.9978 0.9815 0.8571 0.5576 0.4465]*100;
yS2 = [0.9995 0.9978 0.9815 0.8571 0.5576 0.4465]*100;
xSint = interp1(yS(2:end),(-12:-7),50) % 'xS' Must Be Numeric
xS2int = interp1(yS2,xS2,50) % 'xS2' 'yS2=50' Intercept
fig = figure(2);
%Actual plots
plot(xS,yS, '-o','Color','[0, 0.4470, 0.7410]',...
'LineWidth',3.5,'MarkerSize',20,...
'MarkerFaceColor','[0, 0.4470, 0.7410]','MarkerEdgeColor','k',...
'Linewidth',3);
hold on
yline(50, 'r--','Linewidth',3.5);
% Second to calc Ic50 value - uses numeric data
plot(xS2,yS2, '-o','Color','[0, 0.4470, 0.7410]',...
'LineWidth',3.5,'MarkerSize',20,...
'MarkerFaceColor','[0, 0.4470, 0.7410]','MarkerEdgeColor','k',...
'Linewidth',3);
xlabel('Dose [logM]'), ylabel('% Control')
leg = legend({'Cell Number','IC_5_0'});
leg.LineWidth=2.5;
leg.FontSize=28;
leg.NumColumns=1;
leg.LineWidth=2;
% Other plot stuff
box on
ax = gca;
set(gca,'linewidth', 2.5,'fontsize',28,'fontname','Helectiva') % Sets the width of the axis lines, font size, font
set(gca,'TickDir','out')
x0 = 50;
y0 = 50;
width=800;
height=600;
set(gcf,'position',[x0,y0,width,height])
Create a numeric vector for the categorical arrays to work with them, if my approach is incorrect.
.
2 Comments
Star Strider
on 29 Oct 2021
As always, my pleasure!
Your data are such that the interpolation is straightforward. Other times, it requires isolating the region of one or more of the intersections, then interpolating.
You, too!
Enjoy Samhain!
.
More Answers (0)
See Also
Categories
Find more on Bar Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!