2
$\begingroup$

This question already has an answer here:

Starting from the example of the Documentation:

RegionPlot[{x^2 < y^3 + 1, y^2 < x^3 + 1}, {x, -2, 5}, {y, -2, 5}]

Which gives a nice plot with two different colors for each region:

documentation region plot

I now want to provide a List of conditions to the routine instead, hence writing something similar to

a = {x^2 < y^3 + 1, y^2 < x^3 + 1};
RegionPlot[a, {x, -2, 5}, {y, -2, 5}]

which should, in my naive view be equivalent but results in a loss of color differentiation:

enter image description here

So the question is: How can I pass the list to RegionPlot in order to get the same result as directly writing the list as an argument?

Note that for a simple plot the behavior is as I would have expected it:

a = {x^2, x^3};
Plot[a, {x, 0, 1}]

(cannot show because of the link limit)

edit: The behavior is new in Version 10.4.1 and was not present in 10.0 on Windows. I assumed there was a change in syntax. In 10.0 on Windows however there is a bug with the BoundaryStyle directive. It is ignored for a list containing more than 16 regions (for some obscure reason).

b = {False, False, False, False, False, False, False, False, False, 
  False, False, False, False, False, False , False, False, 
  aS <= 0 && bP >= 0, aS >= 0 && bP >= 0 }
RegionPlot[b, {aS, -0.5, 1.}, {bP, -1.5, 1.5}, PlotPoints -> 50,
 FrameLabel -> {"S", "P"},
 PlotStyle -> colors,
 BaseStyle -> {FontSize -> 22},
 BoundaryStyle -> Directive[Black, Thick], Mesh -> None]
$\endgroup$

marked as duplicate by MarcoB, RunnyKine, user9660, m_goldberg, Alexey Popkov May 1 '16 at 4:44

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • $\begingroup$ No such behavior on 10.0 for Mac OS X x86 (64-bit) (December 4, 2014), use ClearAll["Global`*"] FHS $\endgroup$ – user9660 Apr 29 '16 at 16:57
  • $\begingroup$ Sorry for not mentioning that before. The behavior is new in Version 10.4.1 and was not present in 10.0 on Windows. I thought there was a change in syntax. In 10.0 on Windows however the BoundaryStyle directive is ignored for a list containing more than 16 regions (for some obscure reason). $\endgroup$ – Andre Scholich Apr 29 '16 at 16:59
  • 2
    $\begingroup$ @Andre Because of the HoldAll attribute of the plotting functions, you need to evaluate the list $a$ so RegionPlot recognizes that it is a list and attempts to use multiple colors: RegionPlot[Evaluate@a, {x, -2, 5}, {y, -2, 5}]. $\endgroup$ – MarcoB Apr 29 '16 at 17:39
  • 4
    $\begingroup$ For instance the problem was discussed in the case of Plot before: mathematica.stackexchange.com/q/1731/27951 $\endgroup$ – MarcoB Apr 29 '16 at 17:40
3
$\begingroup$

Adding links to comment by MarcoB

Note the Attributes of RegionPlot

Attributes[RegionPlot]

(*  {HoldAll, Protected, ReadProtected}  *)

Since RegionPlot and other plot functions have attribute HoldAll you need to use Evaluate

a = {x^2 < y^3 + 1, y^2 < x^3 + 1};
RegionPlot[Evaluate[a], {x, -2, 5}, {y, -2, 5}]

enter image description here

$\endgroup$
  • $\begingroup$ Thank you, I was mainly confused because of the change of behaviour upon updating from 10.0 to 10.4. $\endgroup$ – Andre Scholich May 2 '16 at 9:40

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