# How to add vertical/horizontal values in a ListLogLogPlot ?

I have to plot on a log-log scale y=f(x) for these data

x = Table[s, {s, 0, 100, 0.1}];
y = Table[Exp[s - 1], {s, 0, 100, 0.1}];
data = Transpose@{x, y};

ListLogLogPlot[data, Joined -> True, PlotRange -> {0.1, 100}]


I would like to add on the same plot the vertical and horizontal lines: x=1, x=3

MAT Version : 13.0

• Have you seen GridLines already? Jul 19, 2022 at 20:14
• @J. M., yes but I don't want the GridLines. Jul 19, 2022 at 20:16
• Show[ListLogLogPlot[{{1,3},{100,3}},Joined->True], ListLogLogPlot[{{1,1},{1,9}},Joined->True], ListLogLogPlot[{{3,1},{3,9}},Joined->True], ListLogLogPlot[data,Joined->True,PlotRange->{0.1,100}]]
– Bill
Jul 19, 2022 at 20:41
• Perhaps you too quickly discarded the suggestion of @J.M.? You can have just two vertical grid lines.
– Alan
Jul 19, 2022 at 23:22

InfiniteLine can be used on plots. In this example we will use the "point, direction" form of InfiniteLine. The coordinates of the point passed to InfiniteLine must be adjusted when the plot scales are logarithmic.

For two vertical lines given by $$x=1$$ and $$x=3$$ and a horizontal line given by $$y=2$$ we can code

abscissas = {1, 3};
ListLogLogPlot[data, Joined -> True, PlotRange -> {0.1, 100},
Epilog -> {InfiniteLine[{Log[#], 1}, {0, 1}] & /@ abscissas,
InfiniteLine[{1, Log[2]}, {1, 0}]}]


My intuition was to use Log[10,x] for the scaling, but using base 10 was wrong. It's the natural log that gives the correct scaling.

For a diagonal line through $$x,y=\{5,10\}$$, code InfiniteLine[{Log[5], Log[10]}, {1, 1}]

Note that the direction used in InfiniteLine[pt,dir] is not logarithmically scaled.

• Thank you @LouisB , please can you add in the same plot the horizontal line y=2? Jul 20, 2022 at 0:36
• It's great @LouisB , thank you so much. Jul 20, 2022 at 0:48

I still believe that GridLines is convenient.

ListLogLogPlot[data, Joined -> True, PlotRange -> {0.1, 100},
GridLines -> {{{1, Directive[Red, Opacity[1]]}, {3,
Directive[Red, Thick, Opacity[1]]}}, {{2,
Directive[Thick, Opacity[1]]}}}]


• Thank you @cvgmt. Jul 20, 2022 at 1:30

Something like:

x = Table[s, {s, 0, 100, 0.1}];
y = Table[Exp[s - 1], {s, 0, 100, 0.1}];
data = Transpose@{x, y};

ListLogLogPlot[data, Joined -> True, PlotRange -> {0.1, 100},
Epilog -> {Red,
Line[{{{Log@1, -3}, {Log@1, -2}}, {{Log@3, -3}, {Log@
3, -2}}, {{-2.6, Log@4}, {-2.4, Log@4}}}]}]


If you want horizontal/vertical lines, simple make the lines longer:

ListLogLogPlot[data, Joined -> True, PlotRange -> {0.1, 100},
Epilog -> {Red,
Line[{{{Log@1, -3}, {Log@1, 100}}, {{Log@3, -3}, {Log@3,
100}}, {{-2.6, Log@4}, {100, Log@4}}}]}]


• @ Daniel Huber thank you, but sorry I wanted to draw the vertical lines x=1, x=3, not the points. Jul 19, 2022 at 20:49
• Simply make the lines longer. I added this to my anwer. Jul 20, 2022 at 6:53