1
$\begingroup$

I use the following link in the forum to plot a graphic in a new windows. However when I use the code to create a new windows using the function described below in question, yes it works but in the new window I see only the results for the last file and not for each files I have (i.e. if I have 3 files, I have three new windows but with the result of the last file in my folder and not with the results of each file...). I would like to create a new windows graphic for each file I have...How to do that in my function ?

CreateDocument[Dynamic[secondDisplay]];
showOnSecond[expr_] := (secondDisplay = expr;);

showOnSecond@ListDensityPlot[...] 

Here the function I use :

file = FileNames["*.dat", NotebookDirectory[]];

func[file_String /; FileExistsQ[file]] := 
 Module[{data, dataT}, data = Import[file, "Table", HeaderLines -> 2];
  dataT = Transpose[data];
  dataT = {dataT[[1]]*10, dataT[[2]]*10, dataT[[3]]};
  dataT[[3]] = 
   Rescale[dataT[[3]], 
    MinMax[dataT[[3]]], {0, 1.}]; (*Rescale z between 0 to 1*) 
  data = Transpose[dataT];

CreateDocument[Dynamic[secondDisplay]];
    showOnSecond[expr_] := (secondDisplay = expr;);

showOnSecond@ListDensityPlot[data,
   ScalingFunctions -> {"Linear", "Linear", "Log10"},
   ImageSize -> UpTo[850],
   AspectRatio -> 1];

 ;
   ;
 ]

func /@ file
$\endgroup$
  • $\begingroup$ Why not ... data = Transpose[dataT]; CreateDocument @ ListDensityPlot[..? It does not work because secondDisplay is a global variable that you use in every plot. $\endgroup$ – Kuba Dec 5 '18 at 14:12
  • $\begingroup$ Yes it works, thanks a lot $\endgroup$ – Bigprophete Dec 5 '18 at 14:27
1
$\begingroup$

As suggested from @Kuba, the following line works well :

CreateDocument@ListDensityPlot[data,
   ScalingFunctions -> {"Linear", "Linear", "Log10"},
   ImageSize -> UpTo[850],
   AspectRatio -> 1];
$\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.