0
$\begingroup$

I have a simple question and it could be very basic tips for many. I tried to find the answer several hours by searching, but couldn't find the way yet. My question is, if I have a data set (x1y1, x2y2, x3y3, x4y4...). What's the most simple and elegant way to plot this data set? How would you do it? Many many thanks in advance.

testdata = {{"", "1st", "", "2nd", "", "3rd", "", "4th"}, {"C", "%", 
    "", "", "", "", "", ""}, {"temp", "result", "", "", "", "", "", 
    ""}, {20, 100, 20, 56, 20, 48, 20, 54}, {40, 98, 40, 85, 40, 45, 
    40, 56}, {60, 39, 60, 64, 60, 73, 60, 45}, {80, 59, 80, 84, 80, 
    14, 80, 5}, {100, 95, 100, 49, 100, 85, 100, 97}};
TableForm@testdata
ListLinePlot[testdata, Frame -> True, Axes -> False, 
 PlotLegends -> testdata[[1]], 
 FrameLabel -> (Style[#, 14] & /@ {testdata[[3, 1]], 
     testdata[[3, 2]]})]

enter image description here

$\endgroup$
1
  • $\begingroup$ The answers of this question depend on the data dimensions and interpretation. The better approaches to visualize categorical data with low number of variables are different than those for numerical data. From the question it is not clear are the "result" columns of testData numerical physical quantity values or contingency values (counts). $\endgroup$ Feb 28, 2016 at 19:26

1 Answer 1

3
$\begingroup$

You need to fundamentally reorganize your data set, and select out empty columns from your plot legend definitions:

reorg = Transpose[{testdata[[4 ;;, 1]], #}] & /@
   Transpose@testdata[[4 ;;, 2 ;; ;; 2]];

ListLinePlot[
  reorg,
  Frame -> True, Axes -> False, 
  PlotLegends -> testdata[[1, 2 ;; ;; 2]], 
  FrameLabel -> (Style[#, 14] & /@ {testdata[[3, 1]], testdata[[3, 2]]})
]

Mathematica graphics

$\endgroup$
4
  • $\begingroup$ Thank you MarcoB for your answer. I will try to learn from your code how to reorganize data-set. $\endgroup$
    – SungwooY
    Feb 28, 2016 at 4:09
  • $\begingroup$ @SungwooYang You are welcome. I'd suggest, however, that it will be much easier on you to generate your data in a more "Mathematica - friendly" way. $\endgroup$
    – MarcoB
    Feb 28, 2016 at 4:15
  • $\begingroup$ I am not sure what is the more mathematica friendly way, but I will definitely try to look and learn. Thank you as always. You're awesome. $\endgroup$
    – SungwooY
    Feb 28, 2016 at 4:23
  • $\begingroup$ Another way: Transpose[Partition[#, 2] & /@ Drop[testdata, 3], {2, 1, 3}]. $\endgroup$ Feb 28, 2016 at 12:23

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.