Only show parts of a line with a certain value?

8 views (last 30 days)
I have a line at the top of my graph that is intended to deliniate when in time there are significant values in the main effect, however where the line dips up (to non-significant values) the curve of the line is visible and it looks like the significance line is longer than it is intended (see image). Making the line invisible and only using markers also does not work as the markers overlap with these non-significant values at the size I need to see the line(see attached image).
TLDR: I would like to know if there is a code to plot the only parts of a line that have values on the y axis that meet a certain theashold. I do not want any other values to be shown other than the ones that are at 200 in this case and none above that so i dont see this little orage flap at the top.
Thanks in advance!
  3 Comments
James Siklos-Whillans
James Siklos-Whillans on 22 Sep 2022
The line is originally just a 1X179 0(nonsig) or 1(sig) matrix. Each cell is the X axis and the contents are the y axis. I plot that line, grab it, and create new variable for anouther line that i can convert the y values into a negative number and multiply that number by 200 like so:
ax = gca;
h = findobj(gca,'Type','line'); %takes the line that was just created and makes it into a new variable "h"
x1 = h.XData; %takes the x data points of the sig line and makes it variable "x1"
y1 = h.YData; %takes the y data points of the sig line and makes it variable "y1"
y2 = ((y1-201)*(-1));%this is how you adjust the y axis of the significance line. it currently is 1 so whatever you want it make it that number, but negative (e.g. you want it to be 1 make this value 2. Want the Sig bar to be at 2.5 make this value 3.5)
Next I plot this line made with new values with the deired formatting:
plot(x1, y2,'b','color',[0.85 0.33 0.1],'MarkerFaceColor',[0.85 0.33 0.1],'lineWidth',15); %plot the sig line on a line with a different y center change the y1*___ to the desired hight of the graph
Does this help at all?
dpb
dpb on 22 Sep 2022
No, not really...seems extremely convoluted way to go about doing anything -- don't see the purpose from just the code and the actual expected result isn't explained clearly, sorry...
Why do you need to retrive the data of "... the line that was just created" by extracting it from a line handle that had to go handle-diving for when if the line was "just created", the x,y data have had to already be available in the variables used in the plot command itself? Why not just use them?
And this thing about burying some magic constant inside the code for the "significance" line is just trouble from the git-go to write code in that manner -- surely there's some reason for choosing whatever number it is that can be written as code logic rather than editing executable code every time...
But, then, all that aside, it's not at all clear what the problem is we're trying to solve -- your original question talked about not displaying points with a given magnitude -- that's what the code provided above would do -- but you're intentionally drawing this line above...so what is/isn't supposed to be shown?
Post a runnable MWE (minimum working example) with a small sample size of data and then explain precisely what it is that is not as desired on the resulting image. We just don't have anything to work with here...

Sign in to comment.

Answers (0)

Categories

Find more on Line Plots in Help Center and File Exchange

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!