Intersection of yline and x,y categorical data

4 次查看(过去 30 天)
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])

采纳的回答

Star Strider
Star Strider 2021-10-29
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
xSint = -7.4815
xS2int = interp1(yS2,xS2,50) % 'xS2' 'yS2=50' Intercept
xS2int = -7.4815
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 个评论
Alistair McQueen
Alistair McQueen 2021-10-29
Okay, I guess it's been a long week... Was not expecting it to pop out as simply as that given the other examples I have been looking at today.
Thanks very much!! That is the correct value. So, I just need to plot it now which is easy. The CTR value is redundant when figuring out this intercept as the y data is a function of that value anyway, so just using the numerical data is fine.
Enjoy your weekend!!
Star Strider
Star Strider 2021-10-29
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!
.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Visual Exploration 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by