I'm working on visualizing critical strain data in Mathematica and would appreciate help plotting my data with error bars. Here's what I'm trying to achieve:
Plot the mean ± standard deviation of several realizations of critical strain as a function of z, on a list-line plot with error bars. Each dataset corresponds to a different value of system size N. I want to show a different curve for each N with its own color and marker (ideally rectangles), with error bars indicating the standard deviation at each value of z.
Here’s a minimal version of the data after parsing my CSV:
(* z-values *)
zValues = {2, 3, 4};
(* One block of 3 realizations of Compression and Shear data *)
compressionData1 = {
{0.1, 0.2, 0.3},
{0.12, 0.22, 0.31},
{0.11, 0.19, 0.29}
};
shearData1 = {
{0.05, 0.1, 0.15},
{0.06, 0.09, 0.14},
{0.04, 0.11, 0.16}
};
compressionData2 = {
{0.2, 0.3, 0.4},
{0.21, 0.31, 0.41},
{0.19, 0.29, 0.39}
};
shearData2 = {
{0.1, 0.15, 0.2},
{0.11, 0.16, 0.21},
{0.09, 0.14, 0.19}
};
blocks = {
<|"N" -> 100, "Compression" -> compressionData1,
"Shear" -> shearData1|>,
<|"N" -> 200, "Compression" -> compressionData2,
"Shear" -> shearData2|>
};
And my code to plot the mean (that works)
p1 = ListLinePlot[Table[Module[{meanCompression},
meanCompression = Mean /@ Transpose[block["Compression"]];
Callout[Transpose[{zValues, meanCompression}],
"N = " <> ToString[block["N"]]]], {block, blocks}],
PlotMarkers -> {Graphics[{Rectangle[{-0.5, -0.5}, {0.5, 0.5}]}], 0.03},
PlotStyle -> {{Dashed}}, Frame -> True,
FrameLabel -> {"z", "Mean Critical Strain"}, ImageSize -> Large]
However when I try to add the errors bars whith the following code, I get an empty figure.
buildAroundData[zVals_, dataMatrix_] := Module[{means, stds},
means = Mean /@ Transpose[dataMatrix];
stds = StandardDeviation /@ Transpose[dataMatrix];
Transpose[{zVals, MapThread[Around, {means, stds}]}]
]
p2 = ErrorListPlot[
Table[{buildAroundData[zValues, block["Compression"]],
PlotStyle -> {ColorData[97][i], Dashed},
PlotMarkers -> {Graphics[{EdgeForm[Black],
FaceForm[ColorData[97][i]],
Rectangle[{-0.5, -0.5}, {0.5, 0.5}]}], 0.03},
PlotLegends -> "Expressions"}, {i,
Length[blocks]}, {block, {blocks[[i]]}}][[All, 1]],
Joined -> True, IntervalMarkers -> "Bands", Frame -> True,
FrameLabel -> {"z", "Mean Critical Compression Strain"},
PlotLabel -> "Compression Strain vs z (All N)",
LabelStyle -> {FontFamily -> "Arial", FontSize -> 12},
ImageSize -> Large];
Thank you so much for your help!


zValues({6,5,8,5,...}) seems to be 13, but that doesn't seem to correspond to the lengths of any of the other data, and yet your code does this comparison:Length[data[[i]]] == Length[zValues]. That's probably not crucial to your main question, but it is an impedance to trying to understand your code well enough to help you. $\endgroup$datathat you imported is in a form that is acceptable to you, then we don't really need to see the source csv data. So, please provide a reduced set of data (maybezValuesof length 3 and just one or two "blocks"). $\endgroup$ListLinePlotthat has the form that you're trying to achieve (can be a very reduced set of data, just something that provides a target form to validate against). $\endgroup$