I'm trying to rewrite a ListDensityPlot
expression to systematiccaly add an option:
SetAttributes[myShow, HoldAll]
myShow[plots__] := With[{
mplots = Hold[{plots}] /. {
ListDensityPlot[args__] :>
ListDensityPlot[args, ColorFunction -> "Rainbow"]
}
}, Show[
Sequence[ReleaseHold[mplots]]
]
]
myShow[
ListDensityPlot[({#1, #2, #1*#2}) & @@@ Tuples[Range[-2, 2], 2]]
]
It looks like it works since the plot is using the ColorFunction specified in my replacement rule. However, alongside the graphic, I also have the error message:
ListDensityPlot::arrayerr -- args__ must be a valid array.
Could you explain what is causing this error message and how to fix that?
ListDensityPlot[args__] :> ...
withHoldPattern[ListDensityPlot[args__]] :> ...
? (ListDensityPlot
does not have theHold
attribute. So we need to preventListDensityPlot[args__]
from being evaluated. $\endgroup$HoldPattern
just after having posted here! I took the liberty to self answer my question below. I tried to explain what was happening to the best of my Mathematica skills. Don't hesitate to correct me if necessary. $\endgroup$Hold*
attributes? $\endgroup$HoldPattern
(as you explain in your answer it is the fact thatRuleDelayed
does not have theHoldAll
attribute). $\endgroup$