1
$\begingroup$

I'm learning mathematica, and right now trying to plot a graph with error bars. What I would like to do is to import 3 lists with x values(1/viscosity), y values(permeance), and error values, and plot this using listplot. I can plot the x vs y values using "Thread" function, however when I try to use "Around" to include errors, I either get problems or no graphs at all. Is it possible to plot the graph in this fashion (I don't want to add error values one by one since I will be having a large number of data points produced, and I would like to keep importing my data from a previously produced excel files).

Example: [1]: https://i.sstatic.net/1sR0U.png

Code:

viscosityinverse = 
Import["C:\\Users\\ilkvi\\Desktop\\Professional\\0-METU CHE \
PhD\\2-Research\\0-Experimental\\Flux Experiments\\Viscosity vs \
Permeance\\Hagen Poiseuille Equations.xlsx", {"Data", 1, All, 2}]

viscosityinverse = Drop[viscosityinverse, 1]

permeance = 
Import["C:\\Users\\ilkvi\\Desktop\\Professional\\0-METU CHE \
PhD\\2-Research\\0-Experimental\\Flux Experiments\\Viscosity vs \
Permeance\\Hagen Poiseuille Equations.xlsx", {"Data", 1, All, 3}]

permeance = Drop[permeance, 1]

error = Import[
"C:\\Users\\ilkvi\\Desktop\\Professional\\0-METU CHE \
PhD\\2-Research\\0-Experimental\\Flux Experiments\\Viscosity vs \
Permeance\\Hagen Poiseuille Equations.xlsx", {"Data", 1, All, 4}]

error = error[error, 1]

ListPlot[Thread[{viscosityinverse, About[Thread[permeance,error]]}]]
$\endgroup$
3
  • $\begingroup$ Please, provide the code you have used so far to import and plot your data. $\endgroup$
    – Domen
    Commented Oct 14, 2021 at 10:45
  • $\begingroup$ Uploaded the code. $\endgroup$ Commented Oct 14, 2021 at 11:13
  • $\begingroup$ 1. Import your data only once with data = Import["..." , {"Data", 1, 2 ;; All}];. 2. Use ListPlot[MapThread[Around, {data[[All, 2]], data[[All, 3]]}]]. $\endgroup$
    – Domen
    Commented Oct 14, 2021 at 11:48

1 Answer 1

1
$\begingroup$
 table = {{"", "1/Viscosity", "Permeance", "Error"}, 
      {"EG", 2.22`*^10, 2.57`, 0}, 
      {"DMSO", 8.7`*^10, 14.09`, 1}, 
      {"Ethanol", 3.03`*^11, 53.67`, 2}, 
      {"UP", 3.6`*^11, 67.5`, 5}, 
      {"Methanol",  6.12`*^11, 110.33`, 16},
      {"Toluene", 6.55`*^11, 101.5`, 0},
      {"EthylAcetate", 8.45`*^11, 112, 0}};

{viscosityinverse, permeance, error} = Transpose @ table[[2 ;;, 2 ;;]];


ListPlot[Thread[{viscosityinverse,  Around @@@ Thread[{permeance, error}]}]]

enter image description here

Variations:

Add labels:

ListPlot[AssociationThread[table[[2 ;;, 1]], 
  Thread[{viscosityinverse,  Around @@@ Thread[{permeance, error}]}]], 
ImageSize -> Large] 

enter image description here

Add the option LabelingFunction -> Tooltip to show labels in tooltips:

enter image description here

Alternatively, as suggested by Bob Hanlon in comments, use

ListPlot[Tooltip[{#, #2}, #3]& @@@
  Thread[{viscosityinverse,  Around @@@ Thread[{permeance,error}], table[[2;;, 1]]}]]

to get the same result.

$\endgroup$
1
  • 1
    $\begingroup$ The OP could also add tooltips with ListPlot[Tooltip @@@Transpose[{Thread[{viscosityinverse, Around @@@ Thread[{permeance, error}]}], table[[2 ;;, 1]]}]] For this data Callout could be used, but the OP refers to a large amount of data which would make Callout too cluttered. $\endgroup$
    – Bob Hanlon
    Commented Oct 14, 2021 at 14:48

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.