# Plot extends beyond given range

I have the following figure

But you can see the lines extend beyond the x value of 30. I'm not sure why this behavior is showing or how I would fix it. Any ideas?

Edit: Here's the code I used to create this plot

Show[
ListLinePlot[{Callout[n1[[;; , 3 ;; 4]], "1", Scaled[0.9]],
Callout[n2[[;; , 3 ;; 4]], "2", Scaled[0.9]],
Callout[n4[[;; , 3 ;; 4]], "4", Scaled[0.2]],
Callout[n8[[;; , 3 ;; 4]], "8", After],
Callout[n16[[;; , 3 ;; 4]], "16", After],
Callout[n32[[;; , 3 ;; 4]], "32", After],
Callout[n64[[;; , 3 ;; 4]], "64", After],
Callout[n128[[;; , 3 ;; 4]], "128", After],
Callout[ntheory[[;; , 3 ;; 4]], "\[Infinity]", After]},
ScalingFunctions -> "Log", PlotRange -> {{0, 30}, {0, 200}},
Axes -> False, Frame -> {True, True, False, False},
FrameLabel -> {Style["T", 14],
Style["(E+1/3)\!$$\*SuperscriptBox[\(n$$, $$2$$]\)", 14]}],
ListLinePlot[{Callout[r1[[;; , 3 ;; 4]],
"1\!$$\*SubscriptBox[\(T$$, $$2$$]\)", Above, Background -> None],
Callout[r2[[;; , 3 ;; 4]], "2\!$$\*SubscriptBox[\(T$$, $$2$$]\)",
Above, Background -> None],
Callout[r3[[;; , 3 ;; 4]], "3\!$$\*SubscriptBox[\(T$$, $$2$$]\)",
Above, Background -> None],
Callout[r4[[;; , 3 ;; 4]], "4\!$$\*SubscriptBox[\(T$$, $$2$$]\)",
Above, Background -> None],
Callout[r5[[;; , 3 ;; 4]], "1\!$$\*SubscriptBox[\(T$$, $$1$$]\)",
Above, Background -> None],
Callout[r6[[;; , 3 ;; 4]], "5\!$$\*SubscriptBox[\(T$$, $$2$$]\)",
Above, Background -> None],
Callout[r7[[;; , 3 ;; 4]], "6\!$$\*SubscriptBox[\(T$$, $$2$$]\)",
Above, Background -> None],
Callout[r8[[;; , 3 ;; 4]], "7\!$$\*SubscriptBox[\(T$$, $$2$$]\)",
Above, Background -> None],
Callout[r9[[;; , 3 ;; 4]],
"8\!$$\*SubscriptBox[\(T$$, $$2$$]\)", {24, 110}, Automatic,
Background -> None],
Callout[r10[[;; , 3 ;; 4]],
"9\!$$\*SubscriptBox[\(T$$, $$2$$]\)", {27, 110}, Automatic,
Background -> None]}, ScalingFunctions -> "Log",
PlotStyle -> Dashed, PlotRange -> {{0, 30}, {0, 200}}
], ImageSize -> Large]


You can see that I give the range of the plot as {0,30}.

Edit 2: Here's the data I'm using

{{0, 1, 6.1559, 0.268762, 1, 0}, {1, 1, 21.2234, 0.316673, 2, 0}, {0,
2, 4.29788, 0.671316, 1, 0}, {1, 2, 12.3117, 1.07505, 2, 0}, {0, 4,
3.33506, 0.972728, 1, 0}, {1, 4, 8.59587, 2.68529, 2, 0}, {2, 4,
14.3822, 3.59775, 3, 0}, {3, 4, 103.51, 5.12115, 9, 0}, {0, 8,
3.15531, 1.12982, 1, 0}, {1, 8, 6.67039, 3.89115, 2, 0}, {2, 8,
10.7852, 7.10209, 3, 0}, {3, 8, 17.1918, 10.7412, 4, 0}, {4, 8,
22.6351, 12.7895, 1, 1}, {5, 8, 28.7645, 14.391, 6, 0}, {6, 8,
49.2471, 17.2008, 8, 0}, {7, 8, 207.019, 20.4846, 18, 0}, {0, 16,
3.10751, 1.17763, 1, 0}, {1, 16, 6.31083, 4.51953, 2, 0}, {2, 16,
9.69797, 9.52761, 3, 0}, {3, 16, 13.3399, 15.5631, 4, 0}, {4, 16,
16.0614, 20.0555, 1, 1}, {5, 16, 17.291, 22.0215, 5, 0}, {6, 16,
21.5697, 28.4074, 6, 0}, {7, 16, 34.3835, 42.9646, 8, 0}, {8, 16,
45.2694, 51.1576, 2, 1}, {9, 16, 73.4464, 63.2197, 14, 0}, {10, 16,
146.495, 74.4367, 21, 0}, {11, 16, 414.038, 81.9384, 36, 0}, {0, 32,
3.09517, 1.1901, 1, 0}, {1, 32, 6.21485, 4.71025, 2, 0}, {2, 32,
9.38272, 10.4148, 3, 0}, {3, 32, 12.6216, 18.078, 4, 0}, {4, 32,
14.5034, 23.2028, 1, 1}, {5, 32, 19.3944, 38.1056, 6, 0}, {6, 32,
22.9672, 49.8306, 7, 0}, {7, 32, 26.6821, 62.2602, 8, 0}, {8, 32,
32.123, 80.2231, 2, 1}, {9, 32, 34.5814, 88.0839, 10, 0}, {10, 32,
43.1396, 113.63, 12, 0}, {11, 32, 47.6313, 125.776, 13, 0}, {12, 32,
71.2611, 176.253, 17, 0}, {13, 32, 90.5376, 204.629, 4, 1}, {14,
32, 292.991, 297.747, 42, 0}, {15, 32, 828.078, 327.754, 72, 0}, {0,
64, 3.09215, 1.19332, 1, 0}, {1, 64, 6.19048, 4.7606, 2, 0}, {2,
64, 9.29984, 10.6613, 3, 0}, {3, 64, 12.4299, 18.8417, 4, 0}, {4,
64, 14.1178, 24.1366, 1, 1}, {5, 64, 15.5828, 29.2084, 5, 0}, {6,
64, 18.7656, 41.66, 6, 0}, {7, 64, 21.9839, 56.0735, 7, 0}, {8, 64,
25.2452, 72.3225, 8, 0}, {9, 64, 28.5489, 90.2278, 9, 0}, {10, 64,
31.906, 109.665, 10, 0}, {11, 64, 45.4461, 196.072, 3, 1}, {12, 64,
69.1626, 352.334, 20, 0}, {13, 64, 95.2646, 503.116, 26, 0}, {14,
64, 152.377, 737.595, 36, 0}, {15, 64, 215.82, 894.86, 46, 0}, {16,
64, 585.985, 1190.99, 84, 0}, {17, 64, 1656.15, 1311.01, 144,
0}, {0, 128, 3.09119, 1.19396, 1, 0}, {1, 128, 6.18433, 4.77331, 2,
0}, {2, 128, 9.28031, 10.728, 3, 0}, {3, 128, 12.3809, 19.0422, 4,
0}, {4, 128, 14.0225, 24.3839, 1, 1}, {5, 128, 15.4878, 29.6946, 5,
0}, {6, 128, 18.6017, 42.6541, 6, 0}, {7, 128, 21.7263, 57.8967, 7,
0}, {8, 128, 24.861, 75.3736, 8, 0}, {9, 128, 28.0055, 95.0272, 9,
0}, {10, 128, 31.1663, 116.839, 10, 0}, {11, 128, 40.7386, 194.506,
13, 0}, {12, 128, 47.2154, 255.886, 15, 0}, {13, 128, 57.1007,
360.945, 18, 0}, {14, 128, 60.4418, 399.07, 19, 0}, {15, 128,
77.577, 609.68, 24, 0}, {16, 128, 90.8961, 784.34, 6, 1}, {17, 128,
102.952, 945.587, 31, 0}, {18, 128, 118.272, 1149.82, 35, 0}, {19,
128, 159.424, 1667.05, 45, 0}, {20, 128, 431.637, 3579.43, 92,
0}, {-1., \[Infinity], 3.09114, 1.19439, 1., 0.}, {-1., \[Infinity],
6.18228, 4.77757, 2., 0.}, {-1., \[Infinity], 9.27342, 10.7495, 3.,
0.}, {-1., \[Infinity], 12.3646, 19.1103, 4.,
0.}, {-1., \[Infinity], 13.9904, 24.4666, 1.,
1.}, {-1., \[Infinity], 15.4557, 29.8598, 5.,
0.}, {-1., \[Infinity], 18.5468, 42.9982, 6.,
0.}, {-1., \[Infinity], 21.638, 58.5253, 7., 0.}, {-1., \[Infinity],
24.7291, 76.4412, 8., 0.}, {-1., \[Infinity], 27.8203, 96.7459, 9.,
0.}, {-1., \[Infinity], 27.9809, 97.8663, 2.,
1.}, {-1., \[Infinity], 30.9114, 119.439, 10.,
0.}, {-1., \[Infinity], 34.0025, 144.522, 11.,
0.}, {-1., \[Infinity], 37.0937, 171.993, 12.,
0.}, {-1., \[Infinity], 40.1848, 201.853, 13.,
0.}, {-1., \[Infinity], 41.9713, 220.199, 3.,
1.}, {-1., \[Infinity], 43.276, 234.101, 14.,
0.}, {-1., \[Infinity], 46.3671, 268.739, 15.,
0.}, {-1., \[Infinity], 49.4582, 305.765, 16.,
0.}, {-1., \[Infinity], 52.5494, 345.18, 17.,
0.}, {-1., \[Infinity], 55.6405, 386.984, 18.,
0.}, {-1., \[Infinity], 55.9618, 391.465, 4.,
1.}, {-1., \[Infinity], 58.7317, 431.176, 19.,
0.}, {-1., \[Infinity], 61.8228, 477.757, 20.,
0.}, {-1., \[Infinity], 64.914, 526.728, 21.,
0.}, {-1., \[Infinity], 68.0051, 578.087, 22.,
0.}, {-1., \[Infinity], 69.9522, 611.664, 5.,
1.}, {-1., \[Infinity], 71.0962, 631.834, 23.,
0.}, {-1., \[Infinity], 74.1874, 687.971, 24.,
0.}, {-1., \[Infinity], 77.2785, 746.496, 25.,
0.}, {-1., \[Infinity], 80.3697, 807.41, 26.,
0.}, {-1., \[Infinity], 83.4608, 870.713, 27.,
0.}, {-1., \[Infinity], 83.9427, 880.797, 6.,
1.}, {-1., \[Infinity], 86.5519, 936.405, 28.,
0.}, {-1., \[Infinity], 89.6431, 1004.49, 29.,
0.}, {-1., \[Infinity], 92.7342, 1074.95, 30.,
0.}, {-1., \[Infinity], 95.8254, 1147.81, 31.,
0.}, {-1., \[Infinity], 97.9331, 1198.86, 7.,
1.}, {-1., \[Infinity], 98.9165, 1223.06, 32.,
0.}, {-1., \[Infinity], 102.008, 1300.69, 33.,
0.}, {-1., \[Infinity], 105.099, 1380.72, 34.,
0.}, {-1., \[Infinity], 108.19, 1463.13, 35.,
0.}, {-1., \[Infinity], 111.281, 1547.93, 36.,
0.}, {-1., \[Infinity], 111.924, 1565.86, 8.,
1.}, {-1., \[Infinity], 114.372, 1635.13, 37.,
0.}, {-1., \[Infinity], 117.463, 1724.7, 38.,
0.}, {-1., \[Infinity], 120.554, 1816.67, 39.,
0.}, {-1., \[Infinity], 123.646, 1911.03, 40.,
0.}, {-1., \[Infinity], 125.914, 1981.79, 9.,
1.}, {-1., \[Infinity], 126.737, 2007.78, 41.,
0.}, {-1., \[Infinity], 129.828, 2106.91, 42.,
0.}, {-1., \[Infinity], 132.919, 2208.43, 43.,
0.}, {-1., \[Infinity], 136.01, 2312.35, 44.,
0.}, {-1., \[Infinity], 139.101, 2418.65, 45.,
0.}, {-1., \[Infinity], 139.904, 2446.66, 10.,
1.}, {-1., \[Infinity], 142.192, 2527.34, 46.,
0.}, {-1., \[Infinity], 145.284, 2638.42, 47.,
0.}, {-1., \[Infinity], 148.375, 2751.88, 48.,
0.}, {-1., \[Infinity], 151.466, 2867.74, 49.,
0.}, {-1., \[Infinity], 154.557, 2985.98, 50., 0.}}


And how I'm assigning my curves:

n1 = Select[data, #[[2]] == 1 &];
n2 = Select[data, #[[2]] == 2 &];
n4 = Select[data, #[[2]] == 4 &];
n8 = Select[data, #[[2]] == 8 &];
n16 = Select[data, #[[2]] == 16 &];
n32 = Select[data, #[[2]] == 32 &];
n64 = Select[data, #[[2]] == 64 &];
n128 = Select[data, #[[2]] == 128 &];
ntheory = Select[data, #[[2]] == \[Infinity] &];
r1 = Select[data, #[[5]] == 1 && #[[6]] == 0 &];
r2 = Select[data, #[[5]] == 2 && #[[6]] == 0 &];
r3 = Select[data, #[[5]] == 3 && #[[6]] == 0 &];
r4 = Select[data, #[[5]] == 4 && #[[6]] == 0 &];
r5 = Select[data, #[[5]] == 1 && #[[6]] == 1 &];
r6 = Select[data, #[[5]] == 5 && #[[6]] == 0 &];
r7 = Select[data, #[[5]] == 6 && #[[6]] == 0 &];
r8 = Select[data, #[[5]] == 7 && #[[6]] == 0 &];
r9 = Select[data, #[[5]] == 8 && #[[6]] == 0 &];
r10 = Select[data, #[[5]] == 9 && #[[6]] == 0 &];


The data is generated from outside code in C++ and I'm just trying to get the data plotted for a paper. I've tried to change the bounds of the PlotRange option but even doing that I get the same result as the figure above.

• If you are asking how to cut the lines off at 30, PlotRange->{0,30} should work. It would be very helpful if you could post the code used to create this! Apr 29, 2019 at 22:17
• Um.... PlotRange -> {{0,50},{0,200}}? Or PlotRange-> {All, Automatic}? Or... Apr 29, 2019 at 23:34
• @DavidG.Stork I've changed the range like you suggest but still get the same kind of overhang I'm trying to avoid. Apr 30, 2019 at 0:05
• @DavidG.Stork I've added the data I'm working with and how I'm assigning the different lines in the plots. Apr 30, 2019 at 2:40

The problem is that the callouts need a significant amount of image padding on the right. Typically, you can use PlotRangeClipping->True to eliminate the parts of the curves that extend beyond the plot range, but in this case that would also eliminate the callouts. A possible workaround is to insert a white rectangle after the plots to wipe out the callouts, and then include another copy of the first plot with the curves suppressed, in order to get the callouts added back.

Here's some code that does this. Let data1 be the data for your first plot, and data2 be the data for you second plot:

data1 = {
Callout[n1[[;;,3;;4]],"1",Scaled[0.9]],
Callout[n2[[;;,3;;4]],"2",Scaled[0.9]],
Callout[n4[[;;,3;;4]],"4",Scaled[0.2]],
Callout[n8[[;;,3;;4]],"8",After],
Callout[n16[[;;,3;;4]],"16",After],
Callout[n32[[;;,3;;4]],"32",After],
Callout[n64[[;;,3;;4]],"64",After],
Callout[n128[[;;,3;;4]],"128",After],
Callout[ntheory[[;;,3;;4]],"\[Infinity]",After]
};

data2 = {
Callout[r1[[;;,3;;4]],"1\!$$\*SubscriptBox[\(T$$, $$2$$]\)",Above,Background->None],
Callout[r2[[;;,3;;4]],"2\!$$\*SubscriptBox[\(T$$, $$2$$]\)",Above,Background->None],
Callout[r3[[;;,3;;4]],"3\!$$\*SubscriptBox[\(T$$, $$2$$]\)",Above,Background->None],
Callout[r4[[;;,3;;4]],"4\!$$\*SubscriptBox[\(T$$, $$2$$]\)",Above,Background->None],
Callout[r5[[;;,3;;4]],"1\!$$\*SubscriptBox[\(T$$, $$1$$]\)",Above,Background->None],
Callout[r6[[;;,3;;4]],"5\!$$\*SubscriptBox[\(T$$, $$2$$]\)",Above,Background->None],
Callout[r7[[;;,3;;4]],"6\!$$\*SubscriptBox[\(T$$, $$2$$]\)",Above,Background->None],
Callout[r8[[;;,3;;4]],"7\!$$\*SubscriptBox[\(T$$, $$2$$]\)",Above,Background->None],
Callout[r9[[;;,3;;4]],"8\!$$\*SubscriptBox[\(T$$, $$2$$]\)",{24,110},Automatic,Background->None],
Callout[r10[[;;,3;;4]],"9\!$$\*SubscriptBox[\(T$$, $$2$$]\)",{27,110},Automatic,Background->None]
};


Then, the following should produce your desired plot:

Show[
ListLinePlot[data1,
ScalingFunctions->"Log",
PlotRange->{{0,30}, {0,200}},
Axes->False,
Frame->{{True, False}, {True, False}},
FrameLabel->{Style["T",14],Style["(E+1/3)\!$$\*SuperscriptBox[\(n$$, $$2$$]\)",14]}
],
ListLinePlot[data2,
ScalingFunctions->"Log",
PlotStyle->Dashed,
PlotRange->{{0,30},{0,200}}
],
Graphics[{White, Rectangle[Scaled[{1, 0}], ImageScaled[{1, 1}]]}],
ListLinePlot[data1,
ScalingFunctions->"Log",
PlotRange->{{0,30}, {0,200}},
PlotStyle->Opacity[0]
],
ImageSize -> Large
]


• That's amazing, thanks so much for the help. Apr 30, 2019 at 3:59
• @Carl Woll thank you very much for the answer. I am also having a similar problem at this time. I was trying to follow your suggestion PlotRangeClipping. But it did not solve the problem. I am using it along with Show. Could you please add some details about PlotRangeClipping solution? Apr 30, 2019 at 9:22
• @Rajendraprasad My point was that PlotRangeClipping is not a viable solution when the callouts extend outside the plot range. You should create a question about your particular issue instead of asking about it in a comment. Apr 30, 2019 at 16:29