2

I have a file with three columns, space separated. First column is x, the second is the data, and the third is the standard deviation I computed of that data.

Now I want to plot in Mathematica, and want the standard deviation on top of the data points.

How do I do that by importing the file ?

rhermans
  • 36,518
  • 4
  • 57
  • 149
Jaswin
  • 183
  • 9

1 Answers1

4

data

First I create an analog to your data.

SystemOpen@SetDirectory[$TemporaryDirectory]

Export[
  "Q175948-data.txt",
  Table[
   N@{i, RandomVariate[NormalDistribution[i, Sqrt[i]]], Sqrt[i]}
   , {i, 100}],
  "TSV"
  ];

Solution

Now the answer

One can load the data using

Import["Q175948-data.txt", "TSV"]

Now you need to format it as explained in the documentation for ErrorListPlot

enter image description here

That can be done using ReplaceAll (/.) (many other ways are possible)

data /. {a_, b_, c_} -> {{a, b}, ErrorBar[c]}

Now load the ErrorBarPlots package

Needs["ErrorBarPlots`"]

Here loading formatting and plot all together

ErrorListPlot[
 Evaluate[
  Import[
    "Q175948-data.txt"
    , "TSV"
    ] /. {a_, b_, c_} -> {{a, b}, ErrorBar[c]}
  ]
 , PlotTheme -> "Scientific"
 ]

enter image description here

rhermans
  • 36,518
  • 4
  • 57
  • 149
  • This works great, but I have a small doubt regarding the plotstyle, my errorbars are very less, so they seem to get covered by large dots, can I change these in some ways ? I tried the usual ListPlot commands to reduce the size of dots, but I am looking to change the color as well, so that it will look distinct. – Jaswin Jun 24 '18 at 18:41
  • That may deserve another question, as moving the goalpost is usually not well received here. Beforer asking you need to be sure you need to. Start by searching in Mathematica documentation, then search this site for similar questions. Only if that it's not enough, collect all the necessary information for somebody to reproduce your problem, don't make us guess. Show explicitly what is wrong and what is that you expect, in detail. Learn about good questions here. – rhermans Jun 24 '18 at 18:55