2
$\begingroup$

Consider the following domain:

reg = RegionPlot[(x^2 + y^2) <= 1 || 2 <= (x^3 + y^2) <= 5, {x, -3, 
    3}, {y, -5, 5}];
sens = {#[[1]], #[[2]]} & /@ 
   Partition[Flatten[Cases[Normal@reg, Line[x_] :> x, Infinity]], 2];

Let us assume that sens is pre-generated. I would like to plot the resulting domain:

ListPlot[sens, Joined -> True]

enter image description here

You may notice a straight line joining the two disconnected regions. Could you please tell me how to avoid their joining for this and other cases?

$\endgroup$
4
  • 4
    $\begingroup$ Do not use Flatten, ListPlot[Cases[Normal@reg, Line[x_] :> x, Infinity], Joined -> True] $\endgroup$
    – cvgmt
    Jun 1, 2023 at 11:51
  • $\begingroup$ alternatively, you can always separate your OR conditions in two plots before you break them. But @cvgmt's answer is by far better! $\endgroup$
    – alex
    Jun 1, 2023 at 11:59
  • 2
    $\begingroup$ @cvgmt I think your comment merits an answer despite the "triviality" of the solution. $\endgroup$
    – alex
    Jun 1, 2023 at 12:01
  • $\begingroup$ @cvgmt : thanks! Would it be possible to export/import the unflattened object as e.g., Table, or some special format would be needed? $\endgroup$ Jun 1, 2023 at 19:43

1 Answer 1

4
$\begingroup$

We can remove Flatten and export the two groups of points to xls with two sheets for further use.

Clear[reg,sens];
reg = RegionPlot[(x^2 + y^2) <= 1 || 2 <= (x^3 + y^2) <= 5, {x, -3, 
    3}, {y, -5, 5}];
sens = Cases[Normal@reg, Line[x_] :> x, Infinity];
Export["test.xls", sens];
SystemOpen["test.xls"]
data = Import["test.xls"];
ListPlot[data, Joined -> True, AspectRatio -> Automatic]
Graphics[{Line@data}]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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