How to draw ranges in a plot?
ranges = RandomReal[10, {10, 2}];
ListPlot[Transpose[ranges],
Filling -> {1 -> {{2}, Directive[Thick, Red]}},
PlotStyle -> None]
if I want the bars to be located at x=1,5,7,12,20,22,30,39,49,51
To specify horizontal coordinates, you can use
ranges = RandomReal[10, {10, 2}];
xvalues = {1, 5, 7, 12, 20, 22, 30, 39, 49, 51};
ListPlot[Transpose[Thread /@ Transpose[{xvalues, ranges}]],
Filling -> {1 -> {{2}, Directive[Thick, Red]}}, PlotStyle -> None]
You can also do it without the Filling
option:
ListLinePlot[Thread /@ Transpose[{xvalues, ranges}],
PlotStyle -> Directive[Red, Thick]]
same picture
Alternatively, you can use Graphics
:
Graphics[{Thick, Red, Line[Thread /@ Transpose[{xvalues, ranges}]]},
Axes -> True, AxesOrigin -> {0, 0}, AspectRatio -> 1 / GoldenRatio]
same picture
Here is @kglr's idea but different set up.
ranges1 = RandomReal[10, 10];
ranges2 = RandomReal[10, 10];
ListPlot[{ranges1, ranges2},
Filling -> {1 -> {{2}, Directive[Thick, Red]}}, PlotStyle -> None]
xvalues = {1, 5, 7, 12, 20, 22, 30, 39, 49, 51};
ranges1 = Transpose@{xvalues, RandomReal[10, 10]};
ranges2 = Transpose@{xvalues, RandomReal[10, 10]};
ListPlot[{ranges1, ranges2},
Filling -> {1 -> {{2}, Directive[Thick, Red]}}, PlotStyle -> None]
Take a look at ErrorListPlot
and ErrorBar
. ErrorListPlot
takes the same options as ListPlot
so you can customize is as you want.
load the ErrorBar Plotting Package first
Needs["ErrorBarPlots`"]
ErrorListPlot[{{2, 0.4}, {1, 0.4}, {3, 0.4}},
PlotRange -> {{0, 4}, {0, 4}}]
The same result with the different syntax:
ErrorListPlot[{{{1, 2}, ErrorBar[0.4]}, {{2, 1},
ErrorBar[0.4]}, {{3, 3}, ErrorBar[0.4]}},
PlotRange -> {{0, 4}, {0, 4}}]