I want to plot g1 and g2 in the same PlotRange. I wrote the following code. But it doesn't work. Please help me.

plotArealElement[r_, phi_, dr_, dphi_] := Module[
 {g1, g2, x, y, u, v, plr},
 g1 = ParametricPlot[s {Cos[phi], Sin[phi]}, {s, r, r + dr}, {psi, phi, phi + 
 u = r {Cos[phi], Sin[phi]};
 v = r {Cos[phi + dphi], Sin[phi + dphi]};
 x = v - u;
 v = (r + dr) {Cos[phi], Sin[phi]};
 y = v - u;
 plr = Options[g1, PlotRange];
 g2 = ParametricPlot[s x + t y, {s, 0, 1}, {t, 0, 1}, plr[[1]]];
 Show[g1, g2]
  • $\begingroup$ (1) Change g1 = ParametricPlot[s {Cos[phi], Sin[phi]}, ...] to g1 = ParametricPlot[s {Cos[psi], Sin[psi]}, ...] and (2) Change plr[[1]] in the line g2 = ... to Evaluate@plr[[1]] $\endgroup$ – kglr Jun 7 '18 at 23:25
  • $\begingroup$ ... or remove plr[[1]] from the line g2 =... $\endgroup$ – kglr Jun 7 '18 at 23:51
  • $\begingroup$ Thank you very much, kglr $\endgroup$ – tchappy ha Jun 7 '18 at 23:52
  1. Fix a typo in definition of g1:

g1 = ParametricPlot[s {Cos[psi], Sin[psi]}, {s, r, r + dr}, {psi, phi, phi + dphi}]
  1. Either remove plr[[1]] in the line defining g2 or change it to Evaluate@plr[[1]]. Note that in both cases Show gets its PlotRange (actually all its unspecified options) from g1 so PlotRange in g2 (whether it is Evaluate @ plr[[1]] or PlotRange-> anything) does not affect the output of Show.

With these changes, plotArealElement works as expected. For example,

plotArealElement[.2, Pi, .1, 2 Pi/3]

enter image description here

plotArealElement[.2, Pi, .1, 3 Pi/2]

enter image description here

| improve this answer | |

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.