5.0

5.0 | 3 ratings Rate this file 19 downloads (last 30 days) File Size: 2.5 KB File ID: #22116

Edit linestyles of plot legends

by Johan Carlson

 

15 Nov 2008 (Updated 12 May 2009)

Code covered by the BSD License  

Simple fix for adding markers to plot legend lines.

Download Now | Watch this File

File Information
Description

If a plot is sampled very densely, and one wants to add markers to the plot, this can be done by plotting two lines on top of each other. One being the smooth line, the other being a down-sampled version with the markers only (e.g. diamonds, squares)

Now, the above is fine as long as we don't need a plot legend, since the legend function will scan for all lines, and what we have is a combination.

This simple script is a work-around to the problem. There is also an example file included showing how to use the function.

MATLAB release MATLAB 7.5 (R2007b)
Zip File Content  
Other Files legendlinestyles.m,
legendlinestyles_test.m
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (5)
02 Mar 2009 Lorgio Teodovich

excellent, thank.

09 May 2009 Martin Huber

very good! please also add color change:

%define colors
colors={'k',[0 0 1]};

%in your function:
%...
if ischar(colors{m})==1
        set(lines(k),'color',char(colors{m}));
else
        set(lines(k),'color',colors{m});
end
%...

11 May 2009 Johan Carlson

Good suggestion. will do!
/Johan

12 May 2009 Johan Carlson

I now posted an updated version, incorporating the changes suggested by Martin. It should be available for download any day now.
/JC

05 Jun 2009 Goutham Mylavarapu

Thanks. I had this problem and your code worked for me. Another code 'hack legend' also works the same way

Please login to add a comment or rating.
Updates
12 May 2009

The function has been updated to also permit changing the color of lines and markers in the legend. The function is still backwards-compatible (so code using version 0.5 should still work)

Tag Activity for this File
Tag Applied By Date/Time
plotting Johan Carlson 17 Nov 2008 11:16:04
plot legend Johan Carlson 17 Nov 2008 11:16:04
plot augmentation Johan Carlson 17 Nov 2008 11:16:04
plot legend Adrian Wanner 25 Jan 2009 17:29:46
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com