-1
$\begingroup$

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.

enter image description here

$\endgroup$
  • 1
    $\begingroup$ 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. $\endgroup$ – user6014 Nov 16 '18 at 22:17
  • $\begingroup$ @user6014 : I have added the relevant information, thank you for the proposition. $\endgroup$ – John Taylor Nov 16 '18 at 22:27
2
$\begingroup$
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}}]

enter image description here

$\endgroup$
1
$\begingroup$

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

enter image description here

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.

$\endgroup$
1
$\begingroup$
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]]

enter image description here

$\endgroup$

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.