View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
Conditionally colored line plot

4.0
4.0 | 4 ratings Rate this file 15 Downloads (last 30 days) File Size: 3.76 KB File ID: #30423 Version: 1.0.0.1
image thumbnail

Conditionally colored line plot

by

Matt Tearle (view profile)

 

15 Feb 2011 (Updated )

Plots (2D line) graph split into two colors above and below a given threshold value

| Watch this File

File Information
Description

Plots vectors x & y using one color for when y is greater than a given threshold value, and another color when y is less than the threshold.
You can optionally specify any standard formatting string that PLOT accepts (eg 'rx:' for a red dotted line with cross markers).

The plotting follows the standard MATLAB PLOT approach of linearly interpolating between data values. The coloring/linestyle changes at y = threshold, even on the interpolated line.

Acknowledgements

This file inspired Conditionally Colored Plot (Ccplot).

MATLAB release MATLAB 7.11 (R2010b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (5)
27 Jan 2017 Ali Amiri

22 Nov 2016 Matt Tearle

Matt Tearle (view profile)

Hi Iliana, Thanks for the feedback. Unfortunately at the moment the function can't handle either of those cases. For multiple columns, you'd just have to hold on and loop over the columns. To do a vertical threshold I guess you could do it horizontally then switch all the x and y data:
>> ax = gca;
>> arrayfun(@(l) set(l,'XData',l.YData,'YData',l.XData),ax.Children)

I'll keep these ideas in mind for future improvements.

Comment only
18 Jun 2016 Iliana Cardenes

HI!!

Thank you for this function! :)

Is there a way to apply it when Y has more than one vector in it? So when every line exceeds a threshold then it changes the colour?

Another question, is there a way for the threshold to apply to the index in X and not the values in Y? So the threshold would appear vertically, not horizontally?

Thank you so much!

Iliana

13 Mar 2014 Barnaby

Barnaby (view profile)

15 Jun 2012 Jeremy

Jeremy (view profile)

  • 1 file
  • 116 downloads
  • 4.87097

It works well as described, but could be improved by handling multiple thresholds.

Updates
01 Sep 2016 1.0.0.1

Updated license

Contact us