Adding Legends

Adding a legend to graphs with many elements can help the final visualization of the graph.

Different legend for different plots

x = -2*pi:.2:2*pi	

% defining x and y values for each line

y1 = sin(x)./x y2 = 2 + sin(x) y3 = 2 + cos(x) y4 = rand(63,3)+3

% FIRST LINE

o1 = struct

% defining options for first line

o1.show = false a1 = area(x,y1,o1)

% SECOND LINE

o2 = o1

% defining options for second line

o2.lineStroke = 'green' a2 = plot(x,y2,o2)

% THIRD LINE

o3 = o1

% defining options for third line

o3.lineStroke = 'purple' o3.markerStroke = 'pink' o3.markerSize = 3 a3 = plot(x,y3,o3)

% FOURTH LINE

o4 = o1

% defining options for fourth line

o4.markerSize = 5 o4.markerShape = 'Triangle' o4.markerFill = '#f2f2f2' a4 = scatter(x,y4,o4)

% FINAL GRAPH

o = struct o.showLegend = true overlay({a1,a2,a3,a4},o)

Related functions

area | bar | histogram | plot | plotyy | scatter | stem