1
$\begingroup$

I have a .csv file that has 12 columns and 511 rows.

data = Import["C:\\Users\\Documents\\data\\AllResults\\result1.csv"];

The first two columns are id tags. I want to plot the last 10 columns of each row as a separate step function.

Do[Print[DiscretePlot[data[[i, k + 2]], {k, 1, 10}, AxesOrigin -> {0, 0}, ExtentSize -> All,
PlotRange -> {{0, 10}, {0, 10}}]], {i, 511}]

(Please feel free to make it prettier)

Now I want to create multiple plots for each unique id in column 1. For example, The first 3 rows of the data have the same column 1 id ("1000_0.01"). I want 4 plots for this id, all in one row, side by side. The first 3 plots are the DiscretePlots of each of the 3 rows in the data and the 4th plot is the summary plot that contains all the 3 plots earlier.

Note: The data is sorted by the first column, so there is no need for searching.

$\endgroup$

1 Answer 1

2
$\begingroup$

Functions:

plot =
 ListLinePlot[#, AxesOrigin -> {0, 0}, Filling -> Bottom,
 InterpolationOrder -> 0,  PlotRange -> {{0, 10}, {0, 10}}, ImageSize -> 200] &;

row[id_, dat_List] := Join[{id}, plot /@ dat, {plot@dat}]

Data:

data = Import["https://raw.githubusercontent.com/bhargavarama/data/master/result1.csv"];

Usage:

row[#[[1, 1]], #[[All, -10 ;;]]] & /@ Partition[data, 3][[37 ;; 39]] // Grid

enter image description here

The part specification [[37 ;; 39]] was just to restrict the range for the example. You can remove it to plot all data.

Note: this code was written assuming there are always three records per tag. For an arbitrary number of records you may use:

row[#[[1, 1]], #[[All, -10 ;;]]] & /@ GatherBy[data, First][[37 ;; 39]] // Grid
$\endgroup$
2
  • $\begingroup$ You never stop to amaze me with your elegant ways!! plot and row functions are neat!! Thank you. +1 $\endgroup$
    – brama
    Commented Jul 30, 2014 at 15:52
  • $\begingroup$ @brama Thanks, and you're welcome. $\endgroup$
    – Mr.Wizard
    Commented Jul 30, 2014 at 17:15

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.