3
$\begingroup$

I'm stacked in a rather silly problem for which I can't find a solution. I have the following list that is composed of 25 elements:

compe = {{"COH180", "graphite", "HM", 0.331346, 0.00365217}, {"COH145","NNO", 
  "graphite", 0.459364, 0.122854}, {"COH189", "graphite", "FMQ", 0.338309, 
  0.0439558}, {"COH149", "graphite", "WM", 0.389052, 
  0.0512205}, {"COH181", "graphite", "CBN", 0.106222, 
  0.00645643}, {"COH151", "VC", "HM", 0.403467, 
  0.0430038}, {"COH152", "VC", "NNO", 0.394097, 
  0.0368108}, {"COH150", "VC", "FMQ", 0.467213, 
  0.132507}, {"COH153", "VC", "WM", 0.346076, 
  0.00775787}, {"COH174", "VC", "CBN", 0.183226, 
  0.0672226}, {"COH175", "MC", "HM", 0.365528, 
  0.0256403}, {"COH156", "MC", "NNO", 0.341335, 
  0.00557104}, {"COH154", "MC", "FMQ", 0.350248, 
  0.0164345}, {"COH157", "MC", "WM", 0.350061, 
  0.0159652}, {"COH182", "MC", "CBN", 0.315711, 
  0.00474534}, {"COH159", "GC", "HM", 0.448654, 
  0.070445}, {"COH160", "GC", "NNO", 0.378951, 
  0.0307073}, {"COH158", "GC", "FMQ", 0.408848, 
  0.0435982}, {"COH161", "GC", "WM", 0.366726, 
  0.0195669}, {"COH176", "GC", "CBN", 0.160936, 
  0.0362919}, {"COH163", "GO", "HM", 0.416089, 0.0514644}, {"COH164", 
  "GO", "NNO", 0.49324, 0.0966641}, {"COH162", "GO", "FMQ", 0.401138, 
  0.0421211}, {"COH165", "GO", "WM", 0.370123, 0.0314981}, {"COH177", 
  "GO", "CBN", 0.500647, 0.100275}}

This list is actually composed of 5 groups, i.e., graphite, VC, MC, GC and GO, and for each of them I could assign a color and a name in this way:

Grph = ListPlot[Table[compe[[l, 4 ;; 5]], {l, 1, 5, 1}], 
  PlotStyle -> {RGBColor[0., 0.38, 0.58], 0.007}, 
  PlotLegends -> {"Graphite"}];

VC = ListPlot[Table[compe[[l, 4 ;; 5]], {l, 6, 10, 1}], 
   PlotStyle -> {RGBColor[1., 0.51, 0.4], 0.007}, 
   PlotLegends -> {"VC"}];

MC = ListPlot[Table[compe[[l, 4 ;; 5]], {l, 11, 15, 1}], 
   PlotStyle -> {RGBColor[0.5, 0.5, 0.5], 0.007}, 
   PlotLegends -> {"MC"}];

GC = ListPlot[Table[compe[[l, 4 ;; 5]], {l, 16, 20, 1}], 
   PlotStyle -> {RGBColor[1., 0.78, 0.06], 0.007}, 
   PlotLegends -> {"GC"}];

GO = ListPlot[Table[compe[[l, 4 ;; 5]], {l, 21, 25, 1}], 
   PlotStyle -> {RGBColor[0.4, 0.7, 1.], 0.007}, 
   PlotLegends -> {"GO"}];

Now, I'm trying with no success to assign to the five elements of each group 5 different markers (possibly some shapes such as circles, triangles, etc.) that will identify in the plot the different buffers used (i.e., HM, NNO, FMQ, WM and CBN). Can someone help me?

I tried this code for the first group, but doesn't work:

markers = {{"\[FilledSquare]"}, {"\[FilledCircle]"}, {"\
\[FilledDiamond]"}, {"\[FilledUpTriangle]"}, \
{"\[FilledDownTriangle]"}};
Grph = ListPlot[Table[compe[[l, 4 ;; 5]], {l, 1, 5, 1}], 
  PlotStyle -> {RGBColor[0., 0.38, 0.58], 0.007}, 
  PlotLegends -> {"Graphite"}, PlotMarkers -> markers]

Thanks in advance for any help!

$\endgroup$
8
  • 2
    $\begingroup$ Welcome to the community. Does ListPlot[List /@ compe[[ 1 ;; 5, 4 ;; 5]], PlotLegends -> {"Graphite"}, PlotMarkers -> Flatten[markers] ] give your desired output ? $\endgroup$
    – Ben Izd
    Commented Jun 30, 2022 at 10:48
  • $\begingroup$ Thank you very much Ben Izd, it works! However, though the markers are actually as I desired, they have different colors...how can I assign the same color, say RGBColor[0., 0.38, 0.58], to all the five markers? $\endgroup$ Commented Jun 30, 2022 at 11:24
  • $\begingroup$ Use PlotStyle -> Directive[RGBColor[0., 0.38, 0.58]] $\endgroup$
    – Ben Izd
    Commented Jun 30, 2022 at 11:26
  • $\begingroup$ Super! Thank you so much! $\endgroup$ Commented Jun 30, 2022 at 11:28
  • $\begingroup$ Sorry, but I would also ask you how can I change the size of all the markers...it seems that Directive command doesn't accept the size option... $\endgroup$ Commented Jun 30, 2022 at 11:55

1 Answer 1

2
$\begingroup$

Mathematica cycle through options like PlotMarkers. One format is {icon1, icon2 , ... } which is equivalent to Flatten[markers] on your case.

If you want to change the marker size, as the documentation suggests, it should be passed along the marker like {{icon1, size1}, {icon2, size2}, ...}. Since you want all of them to be the same size, you can use Thread, so the PlotMarkers would be

ListPlot[ ... , PlotMarkers ->Thread[{Flatten[markers], Offset[15]}] , ... ]

To make all the colors the same you can use Directive[style] as PlotStyle. In your case it would be like this:

ListPlot[ ... , PlotStyle->Directive[RGBColor[0., 0.38, 0.58]] , ... ]

As a side note, instead of using Table to extract data, you can effectively use Part, like below:

compe[[ 1 ;; 5 , 4 ;; 5]]

Since you want to make each of them a separate item, map List so Mathematica gets your intention:

List /@ compe[[ 1 ;; 5 , 4 ;; 5]]

So the final code would look like this:

ListPlot[List /@ compe[[ 1 ;; 5, 4 ;; 5]], PlotLegends -> {"Graphite"}, PlotMarkers ->Thread[{Flatten[markers], Offset[15]}], PlotStyle->Directive[RGBColor[0., 0.38, 0.58]] ]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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