5
$\begingroup$

If you have multiple data sets in one Listplot. Is it possible to change the plotmarker for only one data set? I basically want to keep the default plotmarkers for data sets I do not specify. I would have hoped that

ListPlot[{data1,data2,data3},PlotMarkers->{Automatic,Automatic,"*"}]

would work but it just uses the word Automatic as a plotmarker for the first two sets.


In version 12 the exact functionality I want is implemented with the exact syntax I expected above. I still could use a work around for version 11.

$\endgroup$
  • $\begingroup$ This works for me in Mathematica 12: ListPlot[{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}, PlotMarkers -> {Automatic, Automatic, "*"}] $\endgroup$ – banone Oct 11 '19 at 11:06
  • $\begingroup$ Thanks @banone. You are right. It seems they added exactly the functionality I wanted in version 12. That's nice. I still could use a work around for version 11. (On 11.3 and I guess earlier your example does not work and has the behaviour I described in the question.) $\endgroup$ – Kvothe Oct 11 '19 at 13:08
5
$\begingroup$
{data1, data2, data3} = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}
(* {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}} *)

With Automatic you get

ListPlot[{data1, data2, data3}, PlotMarkers -> Automatic]

Mathematica graphics

To use Automatic for all but one use Show

Show[
 ListPlot[{data1, data2}, PlotMarkers -> Automatic],
 ListPlot[data3, PlotMarkers -> Style["*", 20, Red]],
 PlotRange -> All
 ]

Mathematica graphics

$\endgroup$
2
$\begingroup$

"I still could use a work around for version 11."

As work-around for v11, you can: (1) use PlotMarkers -> Automatic, (2) correct the styling of markers using the function fixMarkers, (3) replace the marker for dataset i with the desired marker using the function replaceMarker[i, marker]:

ClearAll[fixMarkers, replaceMarker]
fixMarkers = Replace[#, {dir_, GeometricTransformation[Inset[a_, b__], c__]} :> {dir, 
  GeometricTransformation[
    Inset[Replace[a, _EdgeForm :> Sequence[EdgeForm[], dir], All], b], c]}, All] &;

replaceMarker[i_, marker_] := Replace[fixMarkers @ #, 
    p : {{___, _GeometricTransformation} .., ___} :>  
     MapAt[# /. Inset[a_, b__] :> Inset[marker, b] &, p, {i}] , All] &;

Example:

data = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}} ;
lp = ListPlot[data, PlotMarkers -> Automatic, ImageSize -> Large];

Row[{lp, replaceMarker[3, Style["*", 24]] @ lp}, Spacer[10]]

enter image description here

$\endgroup$

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.