# How to remove a line from the ListPlot?

Consider the following ListPlot:

Plot1 = RegionPlot[x^2 + y^2 <= 100, {x, 2, 10}, {y, 2, 10}];
Plot1Contour =
Partition[Flatten[Cases[Normal@Plot1, Line[x_] :> x, Infinity]], 2];
ListPlot[Plot1Contour, Joined -> True,
PlotRange -> {{1, 10}, {1, 10}}]


The result is the picture on the left. I would like the result to be displayed as a picture on the right. Is there any way to force Mathematica to display the plot in this way?

Edit. I am looking for a general solution which will remove the vertical lines like the one shown in the example.

• Are you looking for a one-off solution? Or are you looking for a general solution to remove and horizontal lines in your plots? More details would help people provide a better answer.
– ktm
Nov 16, 2018 at 22:17
• @user6014 : I have added the relevant information, thank you for the proposition. Nov 16, 2018 at 22:27

s = 2.001;
Plot1 = RegionPlot[x^2 + y^2 <= 100, {x, 2, 10}, {y, 2, 10}];
Plot1Contour = Partition[Flatten[Cases[Normal@Plot1, Line[x_] :> x, Infinity]], 2];
ListPlot[{Select[Plot1Contour, #[[2]] < s &],
Select[Plot1Contour, #[[2]] > s && #[[1]] > s &]}, Joined -> True,
PlotStyle -> ColorData[97, 1], PlotRange -> {{1, 10}, {1, 10}}]


One relatively manual way to achieve this:

Plot1 = RegionPlot[x^2 + y^2 <= 100, {x, 2, 10}, {y, 2, 10}];
Plot1Contour =
Partition[Flatten[Cases[Normal@Plot1, Line[x_] :> x, Infinity]], 2];
Plot1Contour2 = Rationalize[Chop[Plot1Contour], 1/1000];
minmax = Flatten[{MinimalBy[#, Last], MaximalBy[#, Last]} &[
Cases[Plot1Contour2, {2, _}]], 1];
Position[Plot1Contour2, #] & /@ minmax


{{{2}}, {{22}}}

Using the above I notice that the horizonal points of the form {2,_} take up positions 2;;22 in your list of points. So if I manually omit them I get the nice plot without the vertical line:

ListPlot[Join[Plot1Contour[[22 ;;]], Plot1Contour[[1 ;; 2]]],
Joined -> True, PlotRange -> {{1, 10}, {1, 10}}]


This requires some manual effort, but it achieves what you're after. If it weren't 6PM on a Friday I'd try to come up with something more elegant.

ContourPlot[{x^2 + y^2 - 100,  ConditionalExpression[y - 2, x^2 + y^2 <= 100]},
{x, 2, 10}, {y, 2 - \$MachineEpsilon, 10},
ContourStyle -> Directive[Thick, Blue]]