0
$\begingroup$

I have made a list plot for an excel data set and I got the graph. However, I need to label each graph by its name that is already in the first cell of each column. I have 647 rows and 21 columns, but here is a simple illustration.

As an example: Suppose I have the following table from excel

 A                B               C              D

73.21428571 69.64285714 70.53571429 71.42857143 85.14851485 65.34653465 84.15841584 73.26732673 88.29787234 82.9787234 75.53191489 97.87234043 86.95652174 69.56521739 66.95652174 78.26086957 79.16666667 68.33333333 74.16666667 76.66666667 100 83.65384615 79.80769231 93.26923077 82.53968254 68.25396825 71.42857143 75.3968254 72.34042553 86.5248227 79.43262411 75.88652482 78.98089172 78.98089172 71.33757962 83.43949045 85.32608696 72.82608696 72.82608696 82.06521739

How I can label the ListPlot of the first column by A, and the same thing for other columns?

$\endgroup$
1
  • $\begingroup$ In fact, this is what I have done: mutaz = SemanticImport["Faressystem.xlsx"] mutaz[Transpose /* ListLinePlot] Then I got the graph. The imported file doesn't contain the first letters row $\endgroup$
    – Mutaz
    Apr 25, 2018 at 5:31

2 Answers 2

1
$\begingroup$

If column headers are not part of the data import:

colHeaders = {"A", "B", "C", "D"};
data1 = {{73.21428571, 69.64285714 , 70.53571429 , 71.42857143},
  { 85.14851485 , 65.34653465 , 84.15841584 , 
    73.26732673}, {88.29787234, 82.9787234, 75.53191489, 
    97.87234043}, {86.95652174 , 69.56521739 , 66.95652174, 
    78.26086957}, {79.16666667, 68.33333333, 74.16666667, 
    76.66666667}, {100, 83.65384615, 79.80769231, 
    93.26923077}, {82.53968254, 68.25396825, 71.42857143, 
    75.3968254}, {72.34042553, 86.5248227, 79.43262411, 
    75.88652482}, {78.98089172, 78.98089172, 71.33757962, 
    83.43949045}, { 85.32608696, 72.82608696, 72.82608696, 
    82.06521739}};

ListPlot[Transpose[Rest[data1]], PlotRange -> All, Joined -> True, 
   PlotLegends -> colHeaders]

or, if column headers are part of the data import

data2 = Join[{colHeaders}, data1];
ListPlot[Transpose[Rest[data2]], PlotRange -> All, Joined -> True, 
    PlotLegends -> First[data2]]

and, the way I always import data - into datasets and associations:

data3 = Dataset[AssociationThread[colHeaders -> #] & /@ data1];
ListPlot[Transpose[Normal[data3[Values]]], PlotRange -> All, 
    Joined -> True, PlotLegends -> Normal[data3[1, Keys]]]
$\endgroup$
1
  • $\begingroup$ Thank you so much! @Mitch. I am just wondering, can we use the same code for ListLinePlot? $\endgroup$
    – Mutaz
    Apr 25, 2018 at 7:38
1
$\begingroup$

To answer your question I have a couple questions. You show a first row of A, B, C,... . Is that imported into Mathematica? Or is it the EXCEL spreadsheet display? If it's not imported then you can impute the first 21 letters as labels. If it's part of the import there is a more simple answer, but first an answer to my question.

$\endgroup$
3
  • $\begingroup$ Yes it is. But the ListLinePlot that I need should start from the second row and all columns. I mean I need the list plot for the numbers and label each list line plot by its letter, List line of the first column by A, the second list line plot of the second column by B, ...etc. IF you have an answer for both cases, case if we don't import the first row of A, B, C....and the other case when we import the letters, that would be much appreciated $\endgroup$
    – Mutaz
    Apr 25, 2018 at 4:55
  • $\begingroup$ In fact, this is what I did: mutaz = SemanticImport["Faressystem.xlsx"] mutaz[Transpose /* ListLinePlot] Then I got the graph. The imported file doesn't contain the first letters row $\endgroup$
    – Mutaz
    Apr 25, 2018 at 5:34
  • $\begingroup$ I will give you several examples for your reference, but it's not at all clear to me from the sample data or your description, what you are after. So, my response is dependent on my assumption of your needs. $\endgroup$
    – Mitch
    Apr 25, 2018 at 5:41

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.