Skip to main content

All Questions

Tagged with
8 votes
3 answers
13k views

Dynamic Legend (Updates in every recursion)

I got a for i=1:15. Inside I generate a variable d=1:0.01:10, which is the x'x axis and based on this, I create a continuous function F(d) which has 2 unique variables pitch and yaw. I then plot this ...
Kots's user avatar
  • 501
36 votes
2 answers
65k views

Add custom legend without any relation to the graph

I wish to insert a legend that is not related to the graph whatsoever: figure; hold on; plot(0,0,'or'); plot(0,0,'ob'); plot(0,0,'ok'); leg = legend('red','blue','black'); Now I wish to add it to ...
jarhead's user avatar
  • 1,861
1 vote
2 answers
2k views

Concatenating 2D plots

I have several 2D-plots in MATLAB. In each plot there are some lines (each line is a row-vector of values of fixed length). There is always a base line (black one) and the remaining colored lines may ...
learner's user avatar
  • 1,219
4 votes
2 answers
1k views

Make squared in legend instead of lines Matlab

I have the following code, which plots a 'map' using imagesc, and provides a legend, see output attached. I am trying to replace the lines in the legend with solid squares. My attamps to far leave ...
Hydro202's user avatar
1 vote
1 answer
4k views

One combined legend entry for multiple plots

For some reason, I would like to plot the line and marker of the same data separately. data1 = (1:1:10)'; data2 = (1:2:10); figure(1); plot(data1,data1,'or'); hold on; plot(data2,data2,'-r'); legend('...
cgao's user avatar
  • 165
9 votes
4 answers
49k views

How do I add two legends to a single plot in MATLAB?

I'd like to add two legends to a plot in MATLAB. How can I do this?
Will's user avatar
  • 4,511
2 votes
2 answers
10k views

how to change the sequence of the legend

I want to change the sequence of the legend. See the figure. I want the sequence to be: green and data2, blue and data3, black and data4, red and data1. Could anyone give a demo?
tqjustc's user avatar
  • 3,764
2 votes
1 answer
539 views

How to prevent the legend from updating in R2017a and newer?

Since MATLAB R2017a, figure legends update automatically when adding a plot to axes. Previously, one could do this: data = randn(100,4); plot(data) legend('line1','line2','line3','line4') hold on ...
Cris Luengo's user avatar
  • 59.4k
2 votes
1 answer
4k views

legend for selected plot objects in MATLAB figure

For a MATLAB figure, I have something like: figure; hold on; line ( [1 2], [3 4] ); line ( [5 6], [7 8] ); plot(x1,y1,'r.'); plot(x2,y2,'b.'); where x1,y1,x2,y2 are all vectors. How can I add ...
Chang's user avatar
  • 846
1 vote
2 answers
623 views

Adding a legend when using imagesc, including white for NaN

I have a 35x43 matrix of data with vales ranging from 1-6 and lots of NaNs. I want to NaNs to be white, and the numbers to each be a different colour. I need a legend with the 6 different colour and ...
Hydro202's user avatar
5 votes
1 answer
5k views

Setting a title for a legend in Matlab

The following code is the most Minimal, Complete, and Verifiable example that I could find. My true case is much more complicated: x = 1:0.1:10; y = sin(x); subplot 211 plot(x,y) [leg,att] = legend('...
EBH's user avatar
  • 10.4k
4 votes
2 answers
629 views

Matlab; Pie chart with 2+ / split legends R2017b

I'm creating a pie chart and ideally want the legend to be displayed horizontally at the top and/or bottom. However, in almost all cases this isn't possible as the legend go off the figure. Therefore, ...
Steve's user avatar
  • 634
3 votes
5 answers
16k views

Matlab: change order of entries in Figure legend

I have a Figure file where I would like to change the order of the entries (e.g., put the first entry as third one). I saved this Figure.fig long time ago so I am not sure if I can recover the ...
Patapunfate's user avatar
3 votes
1 answer
717 views

How to change display format of legend in MATLAB

I am looking for a way to force the legend entries in a particular format. I following code, they are displayed like Instead I want it like 1e-1,1e-2,1e-3,1e-4, 1e-5. Is there a way to do this. ...
NAASI's user avatar
  • 173
3 votes
1 answer
1k views

Hide line from legend

I need to hide 4 lines from the legend. I'm using shadedErrorBar so I have 3 line for a sigle group (mean, upper edge of standard deviation and bottom edge) and if i use the classic code legend('line1'...
Shika93's user avatar
  • 637

15 30 50 per page