0
$\begingroup$

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.

$\endgroup$
5
$\begingroup$

Example

Code

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

Output

example output

Reference

Interval
Transpose
NumberLinePlot

| improve this answer | |
$\endgroup$
  • $\begingroup$ very instructive answer +1 :) $\endgroup$ – ubpdqn Jun 22 '16 at 11:16
4
$\begingroup$

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}]

enter image description here

| improve this answer | |
$\endgroup$
  • $\begingroup$ 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. $\endgroup$ – MarcoB Jun 22 '16 at 13:33
  • $\begingroup$ @MarcoB My answer actually utilizes Graphics directly. $\endgroup$ – BoLe Jun 22 '16 at 13:36
  • $\begingroup$ Ah! I apologize, I misread your answer. Thank you for adding the clarification! (+1) $\endgroup$ – MarcoB Jun 22 '16 at 13:39
2
$\begingroup$

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.

Original answer

a = {2, 6, 8, 18, 20, 24, 26} ;
b = {0, 5, 3, 10, 15, 21, 25};
int = Inner[Sort@List@## &, a, b, List];
ListPlot[Transpose@int, Filling -> {2 -> {1}}, PlotStyle -> Blue]

enter image description here

| improve this answer | |
$\endgroup$
  • $\begingroup$ ListPlot[{a, b},... works too, unless I missed something. I still don't know what is OP's goal though. $\endgroup$ – Kuba Jun 22 '16 at 11:09
  • $\begingroup$ @Kuba D'Oh...I guess missing the obvious, Thanks!:) $\endgroup$ – ubpdqn Jun 22 '16 at 11:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.