4
$\begingroup$

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

$\endgroup$
  • 1
    $\begingroup$ A workaround: ListPlot[{Transpose[{x1, y1}], Transpose[{x2, y2}]}, PlotMarkers -> {{\[FilledCircle], 5}, {\[FilledCircle], 0}}, Joined -> True] $\endgroup$ – Anjan Kumar May 26 '17 at 7:51
  • 5
    $\begingroup$ Another workaround: ListLinePlot[{Transpose[{x1, y1}], Transpose[{x2, y2}]}, PlotMarkers -> {{"\[FilledCircle]", 5}, ""}]. $\endgroup$ – J. M.'s technical difficulties May 26 '17 at 7:57
  • $\begingroup$ @J.M Thank you very much ! This is exactly what I was looking for ! :) $\endgroup$ – henry May 26 '17 at 9:42
3
$\begingroup$

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. :)

$\endgroup$
0
$\begingroup$

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!

$\endgroup$
  • $\begingroup$ Thanks !...Have a look at J.M's comment. It's a bit faster. :) $\endgroup$ – henry May 26 '17 at 9:56
  • $\begingroup$ But would you mind to explain how you create your lists ? This looks very interesting. $\endgroup$ – henry May 26 '17 at 9:57
  • $\begingroup$ @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: mathprogramming-intro.org/book/node326.html. You will find a detailed description. $\endgroup$ – Alexei Boulbitch May 26 '17 at 13:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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