0
$\begingroup$

This is really easy in Matlab but I am having a hard time to find an equivalent in Mathematica. I am simply trying to create a convergence plot that I want to add one point in every time step, of course, I don't want to keep redrawing the plot since I might end up having 100000 points in there. I found a solution to have the plot in a separate window but not able stop redrawing it.

BeginPackage["Plotsprt`"];
MainPlotsprt::usage=" ";
Begin["`Private`"];
MainPlotsprt[dt_, conver_,tfinal_]:= Module[{},
obj=CreateDocument[Dynamic[theGraphic],WindowSize->{500,500}];
$DisplayFunction=((CreateDocument[#,obj];#)&);


Do[
   conver=conver-0.0000001;

  theGraphic=ListPlot[{{dt*i,Log10[conver]}},PlotRange->All], 
  {i,tfinal}]

  Return[];
  ];

  SetAttributes[MainPlotsprt,{HoldAll}]
  End[];
  EndPackage[];

 (* Get[FileNameJoin[{NotebookDirectory[], "Plotsprt.wl"}]]; *)
  dt = 0.1;
  conver = 0.001;
  tfinal = 500;
  Plotsprt`MainPlotsprt[dt, conver, tfinal]
$\endgroup$
5
  • $\begingroup$ then don't modify theGraphic at each interation. Create data and once you want to show changes use theGraphic = ListPlot[data, ...]. Is this what you want?> $\endgroup$ – Kuba Apr 23 '18 at 8:21
  • $\begingroup$ @Kuba My ideal approach is to insert one point to the plot in every iteration. I can create blocks of data, let's say 100 points and plot it too but I want to keep the previous 100 points on the plot. I just add 100 more points to existing plot. Removing the theGraphic makes no change. $\endgroup$ – Erdem Apr 23 '18 at 8:37
  • $\begingroup$ There is no way to add points to a plot so you need to build your data table and each 100 steps you need to update theGraphics. $\endgroup$ – Kuba Apr 23 '18 at 8:43
  • $\begingroup$ That is a huge weakness. $\endgroup$ – Erdem Apr 23 '18 at 11:06
  • $\begingroup$ I know: mathematica.stackexchange.com/q/46746/5478 $\endgroup$ – Kuba Apr 23 '18 at 11:25

Your Answer

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

Browse other questions tagged or ask your own question.