I have several datasets,

enter image description here

and I successfully plotted them as points in a Graphic. enter image description here

Then, how can I automatically create legends similar to PlotLegends with a color and a label for each dataset in the graphic? And the colors of the dataset points and the legend are consistent.

My goal is to plot a graph like this

enter image description here

Note: the intervals of x-value of my dataset are not equal, therefore I prefer not to use ListPlot.


closed as off-topic by Bob Hanlon, rhermans, MarcoB, rcollyer, Mr.Wizard Jul 29 '18 at 16:54

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – Bob Hanlon, rhermans, MarcoB, rcollyer, Mr.Wizard
If this question can be reworded to fit the rules in the help center, please edit the question.


Extract your data using the form:

mydata = (Point[{{1, 2}, {3, 4}, {5, 6}}] /. Point -> List)

then ListPlot[mydata, Legended->True]


PlotLegends -> {"mydata1","mydata2"}
  • $\begingroup$ I prefer not to use ListPlot, though. Because the x-value of my dataset is not equally spaced. $\endgroup$ – chika Jul 17 '18 at 3:14
  • $\begingroup$ ListPlot is perfect for datasets in which the $x$-axis data is not evenly distributed. $\endgroup$ – David G. Stork Jul 17 '18 at 3:15
  • $\begingroup$ @chika, ListPlot nicely draws the data in form {{x,y},...}. The alignment of the legend inside the plot can be defined by PlotLegends->Placed[LineLegend[{styles},{labels}],{position}] $\endgroup$ – Rom38 Jul 17 '18 at 4:28
  • 1
    $\begingroup$ ListPlot really works! Thanks everybody. $\endgroup$ – chika Jul 17 '18 at 15:32

Have you checked the documentation yet? Here.

This is an example there.

ListLinePlot[Table[Accumulate[RandomReal[{-1, 1}, 250]], {3}], 
Filling -> Axis, PlotLegends -> {"one", "two", "three"}]

enter image description here


Fake datasets with a structure similar to the structure of your datasets:

graphics = Table[{PointSize[.001], 
 Point @ Transpose[{x = Sort @ RandomInteger[1000, 5000],
    RandomInteger[100] Sin[RandomReal[2 Pi] + RandomReal[2 Pi] x / 500] + 
      RandomReal[5, 5000]}]}, {5}];
g1 = Graphics[graphics, AspectRatio -> 1/GoldenRatio, 
   ImageSize -> 400, Frame -> True];

Colored version of the same:

colors = ColorData[63, "ColorList"][[;; Length@graphics]];
g2 = Graphics[Transpose[{colors, graphics}], 
   AspectRatio -> 1/GoldenRatio, ImageSize -> 400, Frame -> True]

using LineLegend and Legended

labels = Style["dataset " <> ToString[#], 16] & /@ Range[Length@graphics];
legend = LineLegend[Directive[#, AbsoluteThickness[5]] & /@ colors, labels];
Row[{g1, Legended[g2, Placed[legend, {Left, Top}]]}, Spacer[30]]

enter image description here


Not the answer you're looking for? Browse other questions tagged or ask your own question.