4

I have two sets of data:

x1 = Range[0, 10, 0.1];
y1 = Sin[x1];

x2 = Range[0, 10, 0.1];
y2 = Cos[x2];

Now I want to make a ListPlot where the first set is represented as usual with dots and joined, but the second set should only be joined -> no dots.

I tryed:

ListPlot[
 {
  Transpose[{x1, y1}],
  Transpose[{x2, y2}]},
 PlotMarkers -> {{\[FilledCircle], 5}, None},
 Joined -> True
 ]

...which does not work, as you can see:

enter image description here

henry
  • 2,510
  • 14
  • 28

2 Answers2

3

The solutions suggested so far all use glyph-based plot markers which are known to be positioned imprecisely by Mathematica. Here is primitive-based approach that is efficient and produces a publication-quality figure (when exporting to vector graphics formats):

ListLinePlot[{Transpose[{x1, y1}], Transpose[{x2, y2}]}, 
 PlotMarkers -> {{Graphics[{Disk[]}, PlotRangePadding -> 1], .03}, {Graphics[], 0}}]

plot

Note that the above image is exported from Mathematica 8 as PNG and has artifacts due to the fact that the FrontEnd sticks everything to the screen pixel grid when rendering. Exporting as PDF produces a perfect-looking plot (below it is rendered by Adobe Acrobat 11):

Export["i.pdf", %] // SystemOpen

screenshot


But if you really care about the performance (evaluation time, rendering speed, size of the produced vector file), the best what you can do is to construct your graphics from the primitives directly. In your particular case it is simple and straightforward:

Graphics[{{Blue, Line[#], Point[#]} &@Transpose[{x1, y1}],
          {Red, Line[Transpose[{x2, y2}]]}}, Frame -> True, AspectRatio -> 1/GoldenRatio]

plot

As a bonus you get explicit control over positioning of the graphical primitives. :)

Alexey Popkov
  • 61,809
  • 7
  • 149
  • 368
0

Try the following: Here are your lists:

lst1 = Range[0, 10, 0.1] /. x_ /; Head[x] == Real -> {x, Sin[x]};
lst2 = Range[0, 10, 0.1] /. x_ /; Head[x] == Real -> {x, Cos[x]};

And this makes your plot:

Show[{
  ListPlot[lst1, PlotMarkers -> Automatic, Joined -> True, 
   PlotStyle -> Red],
  ListLinePlot[lst2]
  }]

returning the following:

enter image description here

Have fun!

Alexei Boulbitch
  • 39,397
  • 2
  • 47
  • 96
  • Thanks !...Have a look at J.M's comment. It's a bit faster. :) – henry May 26 '17 at 09:56
  • But would you mind to explain how you create your lists ? This looks very interesting. – henry May 26 '17 at 09:57
  • @DoHe Welcome. If you mean to teach me programming a bit, thank you. I know the method used by JM, however. That is the matter of a personal taste only. Now about creating lists. Have a look into the chapter 4 here: http://www.mathprogramming-intro.org/book/node326.html. You will find a detailed description. – Alexei Boulbitch May 26 '17 at 13:32