Message Boards Message Boards

Plot two lines for max/min error on a plot?

Dear all,

How do I plot two parallel lines for maximum and minimum values of relative error percentage as below:

In[124]:= m = {2.2027036725996783`, 
  5.280362701954329`, -1.0124449729925813`, 1.698979465419002`, 
  3.141591718306451`, -2.745060440009399`, -1.6113207086717107`, 
  0.16638391106163822`, -2.258695482994957`, -0.3482598627250328`, 
  4.925577851518227`, 2.6750207005122877`, -4.02288009868453`, 
  2.714952029120464`, 3.034760679525427`, 
  3.729591243576016`, -3.3014545762020924`, -0.22188437300968553`, \
-5.337065768483884`, -4.1220754806842725`, 
  0.5332742419880744`, -2.8743222182737225`, -2.693012697508946`, 
  0.32865798833744514`, 
  4.027192028466991`, -2.8987838601887117`, -0.16628212916201005`, 
  3.484024392679025`, -3.2865991892298494`, -1.4074929511476675`, \
-0.1376591620771673`, -1.340169784223353`, -0.18874557070863454`, \
-0.7158258869527857`, -1.6221568977272842`, 2.220428106758959`, 
  0.18756079584372606`, 2.877020526594872`, 1.6279535082847358`, 
  0.615660929310434`, 
  0.8731989288504256`, -2.4430509995815504`, -3.8101555754900276`, \
-0.41354676208662355`, -3.1882480501258503`, 
  2.797772540468918`, -4.423074431837073`, -0.15315482194415617`, \
-0.9330704276794881`, -2.6279243117503595`, 2.4286072216474692`, 
  3.303587280307156`, 
  3.8085267078688805`, -1.9518727734300068`, -4.213412770426206`, \
-2.357017551327045`, 
  3.4733691167400265`, -0.11673331538713343`, -0.40688016301067764`, 
  1.6698198640343067`, 0.14831028096303508`, 0.24317430279547272`, 
  3.011211821071481`, -0.48218554546387205`, 0.09689880402434317`, 
  1.191374402522961`, -2.7963094788933693`, -1.7336554568628828`, 
  0.7339703452354714`, -0.8739780822047689`, -3.63379798637767`, 
  1.0591084727706641`, 5.324198415974884`, 
  0.0845454122567755`, -3.991208337015724`, -3.793925049867107`, 
  1.8074800549551044`, 1.1480036635543738`, -2.7476419011691475`, 
  1.00023361017206`, 0.028334302480905814`, -0.008048998604257977`}

In[129]:= {Max[m], Min[m]}

Out[129]= {5.3242, -5.33707}

In[130]:= ListLinePlot[m, LabelStyle -> {14, GrayLevel[0], Bold}, 
 ImageSize -> 500, PlotStyle -> Blue, 
 AxesLabel -> {"Sample", "Relative Error (%)"}, Filling -> Axis, 
 PlotRange -> All]

enter image description here

Many thank!

POSTED BY: M.A. Ghorbani
4 Replies

Mohammad,

Glad to be of assistance. I think you are correct except your approach will miss any points that are exactly 0. You may want to use

up = Select[m, 5 > # >= 0 &]
down = Select[m, 0 > # > -5 &]

to put any 0 values in the "up"

Regards,

Neil

POSTED BY: Neil Singer

Also, note that version 12.0 adds error bars to various plots. See IntervalMarkers as a start.

Regards,

Neil

POSTED BY: Neil Singer

Thank so much Neil. I really appreciate you.

For the determination of how many percentages the data is between [-5%,+5%], I did below computations. Is it correct?

In[61]:= Length[m]

Out[61]= 82

In[62]:= up = Select[m, 5 > # > 0 &]

Out[62]= {2.2027, 1.69898, 3.14159, 0.166384, 4.92558, 2.67502, \
2.71495, 3.03476, 3.72959, 0.533274, 0.328658, 4.02719, 3.48402, \
2.22043, 0.187561, 2.87702, 1.62795, 0.615661, 0.873199, 2.79777, \
2.42861, 3.30359, 3.80853, 3.47337, 1.66982, 0.14831, 0.243174, \
3.01121, 0.0968988, 1.19137, 0.73397, 1.05911, 0.0845454, 1.80748, \
1.148, 1.00023, 0.0283343}

In[63]:= down = Select[m, 0 > # > -5 &]

Out[63]= {-1.01244, -2.74506, -1.61132, -2.2587, -0.34826, -4.02288, \
-3.30145, -0.221884, -4.12208, -2.87432, -2.69301, -2.89878, \
-0.166282, -3.2866, -1.40749, -0.137659, -1.34017, -0.188746, \
-0.715826, -1.62216, -2.44305, -3.81016, -0.413547, -3.18825, \
-4.42307, -0.153155, -0.93307, -2.62792, -1.95187, -4.21341, \
-2.35702, -0.116733, -0.40688, -0.482186, -2.79631, -1.73366, \
-0.873978, -3.6338, -3.99121, -3.79393, -2.74764, -0.008049}

In[64]:= Percentage = (Length[up] + Length[down])/Length [m]

Out[64]= 79/82
POSTED BY: M.A. Ghorbani

I think this is a start. You can adjust the formatting from here.

ListLinePlot[{m, {{0, Max[m]}, {Length[m], Max[m]}}, {{0, 
    Min[m]}, {Length[m], Min[m]}}}, 
 LabelStyle -> {14, GrayLevel[0], Bold}, ImageSize -> 500, 
 PlotStyle -> {Blue, Directive[Red, Dashed, Thick], 
   Directive[Red, Dashed, Thick]}, 
 AxesLabel -> {"Sample", "Relative Error (%)"}, 
 Filling -> {Axis, None, None}, PlotRange -> All, 
 PlotLabels -> {None, 
   Style["Max=" <> ToString[Round[Max[m], 0.01]], Red], 
   Style["Min=" <> ToString[Round[Min[m], 0.01]], Red]}]

enter image description here

Regards,

Neil

POSTED BY: Neil Singer
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract