2
$\begingroup$

I draw Cos function using the code line :

GraphicsColumn[
  {
   Plot[Cos[0.0625*Pi x], {x, 0, 40*Pi}, Axes -> False], 
   Plot[Cos[0.0625*Pi x], {x, 0, 40*Pi}, Axes -> False], 
   Plot[Cos[0.0625*Pi x], {x, 0, 40*Pi}, Axes -> False], 
   Plot[Cos[0.0625*Pi x], {x, 0, 40*Pi}, Axes -> False]
  }
  ,ImageSize -> Large
]

and manually add circles and arrows as you can see in the attached picture , how can I export the figure . export doesn't work and I can't save it or copy it please help
see image

$\endgroup$
1
  • $\begingroup$ I don't know how to edit from Word, but if I add arrows to a sine plot using the drawing tools and then export the graphic, it seems to work fine. See here $\endgroup$
    – user1066
    Commented Jul 30, 2018 at 18:27

2 Answers 2

2
$\begingroup$

I know this post could be shorter, but I wanted to outline a methodology, as in teach a man to fish..., so please bear with me. The first point to make is that the geometric scale of x vs y is easiest to manage from within the Graphics[] environment. Each Plot[] command creates its own coordinate context and so you can introduce distortions you don't intend unless you apply a great deal of care. Secondly, mixing different graphical elements is easiest to do in Graphics[] as well.

First of all, decide how to draw the 4 cosine curves. I noticed that your diagrams simply have 4 cycles and no axes so I dispensed with the frequency and duration you used. Here we have a quick set of 4 cosines in a column:

With[{baseline = -2.5 {0, 1, 2, 3}, t = Range[-2, 2, 0.01]},
    Module[{s},
        s = Cos[2 Pi t];
        Graphics[{
            Table[Line@Thread@{t, s + baseline[[k]]}, {k, 1, 4}]
        }]
    ]
]

enter image description here

Notice I separated the curves by a little more than their peak to peak height.

Now we want to draw the dots in a systematic way. Imagine each set of dots is drawn with respect to a point on the baseline associated with the cosine curve. We can use the baseline index to also choose that time position.

With[{baseline = -2.5 {0, 1, 2, 3}, t = Range[-2, 2, 0.01], tdots = {-1.5, -0.5, 0.5, 1.5}},
    Module[{s, dots},
        s = Cos[2 \[Pi] t];
        dots[k_] := With[{td = tdots[[k]], y0 = baseline[[k]] + 0.15, dy = 0.4, r = 0.16},
            {Red, Disk[{td, y0 + dy}, r], Disk[{td, y0}, r], Disk[{td, y0 - dy}, r]}
        ];
        Graphics[{
            Table[Line@Thread@{t, s + baseline[[k]]}, {k, 1, 4}],
            Table[dots[k], {k, 1, 4}]
        }]
    ]
]

enter image description here

Now let's add the arrows. We will call them hop's. Here we will also assign the output to the variable g for export below.

g = With[{baseline = -2.5 {0, 1, 2, 3}, t = Range[-2, 2, 0.01], 
    tdots = {-1.5, -0.5, 0.5, 1.5}},
    Module[{s, dots, hop},
        s = Cos[2 \[Pi] t];
        dots[k_] := 
        With[{td = tdots[[k]], y0 = baseline[[k]] + 0.15, dy = 0.4, r = 0.16},
            {Red, Disk[{td, y0 + dy}, r], Disk[{td, y0}, r], Disk[{td, y0 - dy}, r]}
        ];
        hop[k1_, k2_] := With[{y = baseline[[k1]] + 1, t1 = tdots[[k1]], t2 = tdots[[k2]]},
        Arrow[BezierCurve[
            {{t1, y}, {0.9 t1 + 0.1 t2, y + 0.5}, {0.1 t1 + 0.9 t2, y + 0.5}, {t2, y}}]
        ] ];
        Graphics[{
            Table[Line@Thread@{t, s + baseline[[k]]}, {k, 1, 4}],
            Table[dots[k], {k, 1, 4}],
            hop[1, 2], hop[2, 3], hop[3, 4], hop[4, 1]
        }]
    ]
]

enter image description here

You want to export to a pixel oriented format like png as opposed to a photographic image format like jpg because the jpg image compression can introduce artifacts. This command will save the png file in the same directory as the notebook containing this code.

Export[FileNameJoin[{NotebookDirectory[], "dot_hops.png"}],g,ImageResolution->200]
$\endgroup$
3
  • $\begingroup$ I appreciate that a lot thank you very much I am a beginner user of mathematica your explaination helps alot $\endgroup$
    – maya
    Commented Aug 1, 2018 at 11:57
  • 1
    $\begingroup$ Your thanks are my reward, but would you mind accepting my answer? $\endgroup$
    – user7739
    Commented Aug 1, 2018 at 23:55
  • $\begingroup$ how I can change your code so instead of 3 balls in one site ,I would have 2 balls in site and 1 ball in the next neighbor site ? I would appreciate so much if you can answer me , thanks in advance $\endgroup$
    – maya
    Commented Sep 18, 2018 at 9:29
1
$\begingroup$

If you can adapt this then Export works just fine

g1 = GraphicsColumn[{
  Plot[Cos[0.0625*Pi x], {x, 0, 40*Pi}, Axes -> False, 
   Epilog -> {Disk[{5 Pi, 3/4}, {8, .2}], Disk[{5 Pi, 1/4}, {8, .2}],
   Arrowheads[{-.05, .05}], 
   Arrow[BezierCurve[{{5 Pi, 1.1}, {10 Pi, 1.3}, {15 Pi, 1.1}}]]}, 
   PlotRange -> {-1, 1.5}], 
  Plot[Cos[0.0625*Pi x], {x, 0, 40*Pi}, Axes -> False, 
   Epilog -> {Disk[{10 Pi, 3/4}, {8, .2}], Disk[{10 Pi, 1/4}, {8, .2}]
  }]}, ImageSize -> Large]
Export["g1.jpg", g1]

enter image description here

$\endgroup$
5
  • $\begingroup$ thanks ! but how can I add the arrow ? $\endgroup$
    – maya
    Commented Jul 30, 2018 at 16:24
  • $\begingroup$ Exactly how did you add the arrow to your plot? Perhaps you can do the same thing, but I cannot know without seeing what you did. $\endgroup$
    – Bill
    Commented Jul 30, 2018 at 16:25
  • 1
    $\begingroup$ I copy the curved arrow from word to mathematica $\endgroup$
    – maya
    Commented Jul 30, 2018 at 16:27
  • $\begingroup$ Option 1: Use software like Adobe to combine exported graphics from Mathematica with exported graphics from Word. Option 2: Learn how to fiddle with the unending details of creating graphics inside Mathematica to generate the arrows that look the way you want them to. See above for a very simple example of this. Option 3: Generate all the graphics inside Adobe or inside PostScript. $\endgroup$
    – Bill
    Commented Jul 30, 2018 at 16:45
  • $\begingroup$ Or, option 4, use the Drawing Tools (or other software?) to modify the graphic within Mathematica and then export the modified graphic (+1) $\endgroup$
    – user1066
    Commented Jul 30, 2018 at 19:48

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.