# plotting difference intervals of two vectors

IF $a=\{2,6,8,18,20,24,26\}$ and $b=\{0,5,3,10,15,21,25\}$. I want the interval of the pairwise differences, that is, [0,2], [5,6], etc showing by lines in plots. I don't know the command for it. I tried for the difference "a-b" and plot but it gives only the points on the graph. Thank you for help.

## Example

Code

NumberLinePlot[(Interval @ # & /@ Transpose[{b, a}]), PlotLegends -> "Expressions"]


Output

Reference

• very instructive answer +1 :) Jun 22, 2016 at 11:16

In addition to NumberLinePlot -- which is a version 10 function -- one can customize a Graphics function.

plot[
from_List,
to_List, opts___] /; Length[b] == Length[a] :=
Module[{z = 0, lines},
lines = Apply[
Module[{ends},
ends = {{#1, z}, {#2, z}};
z++;
{Gray, Dashed, Thin, Line[{{#[[1]], 0}, #}] & /@ ends,
ColorData[3][z], Dashing[{}], Thick, Point[ends],
Line[ends]}] &,
Transpose[{from, to}], 1];
Graphics[{Thick, PointSize[Medium], lines}, opts]
]


For example:

plot[b, a,
ImageSize -> Medium,
Axes -> {True, False}]


• BoLe, could you point out more clearly what you perceive as different between your answer and that by @E.Doroskevic above? You both use NumberLinePlot, and frankly the other answer is rather more readable at first glance. Jun 22, 2016 at 13:33
• @MarcoB My answer actually utilizes Graphics directly.
– BoLe
Jun 22, 2016 at 13:36

I am not sure I understand what the aim. Here is one interpretation.

As Kuba points out in comment:

ListPlot[{a,b},Filling -> {2 -> {1}}, PlotStyle -> Blue]

suffices.

a = {2, 6, 8, 18, 20, 24, 26} ;

• ListPlot[{a, b},... works too, unless I missed something. I still don't know what is OP's goal though.