1
$\begingroup$

I have data from an experiment with about 500 rows and five columms. I have learnt from this forum how to import my data with the code.

importeddata = Import["sample.xlsx"][[1]]; Grid[importeddata]

My problem now is that I wish to make 3D (ListdensityPlot) and 4D (ListdensityPlot3D) plots from these data in which I can select the columns to be plotted against one another. That is, I can specify 3 columns to be used for 3D and four columns to be used for 4D within the code. Secondly, I want the selected column headings be automatically labeled across the axes and my last selected column be colored legends by the right hand side of the plots. I actually have a code but it is too poor to be shown here. I would be deeply grateful for your opinions and suggestions. Thanks.

EDITS: Please see my data below (reduced to just 16 rows) here!. I want to be able to select either Force or Power to be plotted against Time vs (a) either x or y for 3D (b) x and y for 4D. Thanks once more!

$\endgroup$
  • 1
    $\begingroup$ Can you upload your data to see the result? $\endgroup$ – Alex Trounev Jul 9 '18 at 18:02
  • $\begingroup$ Thank you Alex, I have edited my question as you have recommended. $\endgroup$ – Dean Jul 9 '18 at 22:09
  • 1
    $\begingroup$ Dean, this is not data, it's a picture. Upload your data in the original format. We must see the result of the code. $\endgroup$ – Alex Trounev Jul 10 '18 at 12:53
  • $\begingroup$ Hi Alex, I have made necessary modifications to my question. Thanks! $\endgroup$ – Dean Jul 11 '18 at 1:19
3
$\begingroup$
data = {{0, 93, 84, 55, 99}, {10, 58, 85, 70, 79}, {20, 30, 60, 95, 
    95}, {32, 29, 78, 22, 70}, {33, 6, 97, 21, 46}, {43, 24, 39, 13, 
    13}, {50, 94, 12, 93, 76}, {51, 1, 26, 44, 74}, {51, 15, 79, 64, 
    2}, {57, 43, 23, 71, 67}, {59, 93, 17, 2, 17}, {69, 8, 79, 13, 
    6}, {70, 76, 98, 51, 67}, {71, 79, 85, 54, 64}, {73, 93, 16, 79, 
    80}};

Legended[ListDensityPlot[data[[All, {1, 2, 4}]], 
  FrameLabel -> {"Time", "x"}, ColorFunction -> "ThermometerColors"], 
 Placed[BarLegend[{"ThermometerColors", MinMax@data[[All, 4]]}, 
   LegendLabel -> 
    Placed["Force (N) ", Right, Rotate[#, 90 Degree] &]], Right]]

enter image description here

Legended[ListDensityPlot3D[data[[All, {1, 2, 3, 4}]], 
  AxesLabel -> {"Time", "x", "y"}, 
  ColorFunction -> "ThermometerColors"], 
 Placed[BarLegend[{"ThermometerColors", MinMax@data[[All, 4]]}, 
   LegendLabel -> 
    Placed["Force (N) ", Right, Rotate[#, 90 Degree] &]], Right]]

enter image description here

$\endgroup$
  • $\begingroup$ Thank you so much, Okkes Dulgerci. The codes worked excellently. My problem is now solved! $\endgroup$ – Dean Jul 13 '18 at 2:18
  • 1
    $\begingroup$ My pleasure! You can accept it by clicking accept. $\endgroup$ – OkkesDulgerci Jul 13 '18 at 2:21
  • $\begingroup$ Done! Thanks once again. $\endgroup$ – Dean Jul 13 '18 at 2:25
1
$\begingroup$

Your data is not smooth, however, is this what you are looking for?:

    importeddata =Import["forcemap.xlsx"][[1]];Grid[importeddata]
    xt = Table[{importeddata[[i,1]], importeddata[[i,2]]}, 
    {i,2,Length[importeddata[[All, 2]]]}];

    (* {{0., 93.}, {10., 58.}, {20., 30.}, {32., 29.}, {33., 6.}, {43., 
    24.}, {50., 94.}, {51., 1.}, {51., 15.}, {57., 43.}, {59., 
    93.}, {69., 8.}, {70., 76.}, {71., 79.}, {73., 93.}} *)

    ListPlot[xt, Joined -> True]

    (* the plot of x vs t *)

    fxy = Table[{importeddata[[i, 2]], importeddata[[i, 3]], 
    importeddata[[i, 4]]}, {i, 2, Length[importeddata[[All, 2]]]}];
    ListPlot3D[fxy]

    (*the plot of the force vs x and y*)

For any other plot just select the column in the second coordinate of "importeddata".

$\endgroup$
  • $\begingroup$ Thanks Gluoncito!! $\endgroup$ – Dean Jul 13 '18 at 2:23
1
$\begingroup$

Using data from your Excel sample file, we select columns for ListDensityPlot and ListDensityPlot3D. The plots are automatically labeled for the columns we select.

data = {{"Time{s}", "x(m)", "y(m)", "Force(N)", "Power(W)"}, {0, 93, 
    84, 55, 99}, {10, 58, 85, 70, 79}, {20, 30, 60, 95, 95}, {32, 29, 
    78, 22, 70}, {33, 6, 97, 21, 46}, {43, 24, 39, 13, 13}, {50, 94, 
    12, 93, 76}, {51, 1, 26, 44, 74}, {51, 15, 79, 64, 2}, {57, 43, 
    23, 71, 67}, {59, 93, 17, 2, 17}, {69, 8, 79, 13, 6}, {70, 76, 98,
     51, 67}, {71, 79, 85, 54, 64}, {73, 93, 16, 79, 80}};

Choose the columns to plot. For example, use:

select2D = {1, 2, 4}; (*time,x,force*)

or

select2D = {1, 3, 5}; (*time,y,power*)

Automatically select labels and display with ListDensityPlot.

lbls = First[data][[select2D]];

ListDensityPlot[Rest[data[[All, select2D]]], FrameLabel -> Most@lbls, 
 PlotLegends -> 
  Placed[BarLegend[Automatic, LegendLabel -> Last@lbls], {After, 
    Top}]]

ListDensityPlot

The method is similar for ListDensityPlot3D - we select columns to plot:

select3D = {1, 2, 3, 4};(*time,x,y,force*)

or

select3D = {1, 2, 3, 5};(*time,x,y,power*)

Automatically select labels and display with ListDensityPlot3D.

lbls = First[data][[select3D]];

ListDensityPlot3D[Rest@data[[All, select3D]], AxesLabel -> Most@lbls, 
 PlotLegends -> 
  Placed[BarLegend[Automatic, LegendLabel -> Placed[Last@lbls, Top]], 
   Right]]

ListDensityPlot3D

$\endgroup$
  • $\begingroup$ Thank you so much, creidhne. The modular presentation of your response is quite good. Thanks! $\endgroup$ – Dean Jul 13 '18 at 2:21

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.