3
$\begingroup$

I have the following data which is in the form of irregular/non rectangular arrays

list1 = {{1}, {2}, {3}, {4}, {5, 6, 7}, {8, 9, 10}, {11}, {12}}

To transpose it for plotting, I have to use (because of the irregular shape)

list2 = Flatten[list1, {{2}, {1}}]

This is now a $3\times1$ column. I want to plot this data, So I use the ListLinePlot as

ListLinePlot[list2, DataRange -> {1, 3}, Frame -> True] 

The three rows are plotted as three curves, but the problem is that the upper two curves which correspond to the second and third row of list2 also start from 1 on the x-axis.? Shouldn't they start from 2 instead of 1? I thought I could use PadLeft or PadRight with empty entries {} to the left or right of the last two (2 element) rows of list2 (to make them 6 element rows, like the first row of list2) to force the two curves to start from 2, but I failed. Could someone tell any workaround?

$\endgroup$
2
  • 1
    $\begingroup$ Does ListLinePlot[Transpose[PadRight[list1]], DataRange -> {1, 3}] do what you want? $\endgroup$ Commented Mar 14, 2019 at 6:00
  • $\begingroup$ @J.M.isslightlypensive Thanks. But it gives zeros on right and left which actually do not do the trick, however, if they are somehow empty, would do the trick. $\endgroup$
    – AtoZ
    Commented Mar 14, 2019 at 6:20

1 Answer 1

5
$\begingroup$
ListLinePlot[Transpose[PadRight[list1, Automatic, Null]], 
 DataRange -> {1, 3}]

enter image description here

$\endgroup$
1
  • $\begingroup$ Thanks. It works perfectly.. $\endgroup$
    – AtoZ
    Commented Mar 15, 2019 at 3:24

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.