TransWikia.com

How to change the ● to ◆ in the given code by using MeshStyle?

Mathematica Asked on December 28, 2020

I use this code

ListPlot[Table[{n, Sin[2 n^2]}, {n, 1, 10}], 
  Frame -> True, 
  Joined -> True, 
  PlotStyle -> Directive[Blue, LineColor -> LightRed], 
  Mesh -> All, 
  PlotRange -> All, 
  Axes -> None]

and I get

enter image description here

Is it possible to change the to using MeshStyle?

I can get the desired result by

ListPlot[Table[{n, Sin[2 n^2]}, {n, 1, 10}], 
 Frame -> True, 
 Joined -> True, 
 PlotStyle -> Directive[Blue, LineColor -> LightRed], 
 PlotMarkers -> {"◆"}, 
 PlotRange -> All, 
 Axes -> None]

but this does not help me, since in the domain I need to plot, some undesirable space arises between plot markers and the joined line.

2 Answers

Instead of a font glyph, you can use a graphics object as plot marker.

ChartElementData["FilledMarkers"] gives the list of filled markers:

ChartElementData["FilledMarkers"] // Row

enter image description here

The third one is what we need:

filleddiamond = ChartElementData["FilledMarkers"][[3, 1, 1]]; 

ListPlot[Table[{n, Sin[2 n^2]}, {n, 1, 10}], Frame -> True, Joined -> True, 
 PlotStyle -> Directive[Blue, LineColor -> LightRed], 
 PlotMarkers -> {Graphics @ filleddiamond, .05}, 
 PlotRange -> All, Axes -> None]

enter image description here

Correct answer by kglr on December 28, 2020

You could just replace points to diamonds:

ListPlot[Table[{n, Sin[2 n^2]}, {n, 1, 10}], Frame -> True, 
  Joined -> True, PlotStyle -> Directive[Blue, LineColor -> LightRed],
   Mesh -> 20, PlotRange -> All, 
  Axes -> None] /. {Point[
    pts_] :> (Inset["◆", #] & /@ pts)}

Answered by halmir on December 28, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP