I have a figure obtained from ParametricPlot, which is relatively costly to obtain.

For example:

enter image description here

I would like to offset the picture in terms of a parameter, for example x1, so that the figure is drawn at (x1, 0) instead of at (0, 0). In other words, I would like to apply a transformation consisting of a slide over the X axis.

I have tried with Translate and GeometricTransformation but it does not seem to work on plot outputs.

Is this possible?

  • $\begingroup$ Please, post your code to get help. Meanwhile, just add a constant $x_1$ to your $f_x$ component in ParametricPlot. $\endgroup$ – José Antonio Díaz Navas Mar 26 '18 at 13:35
  • $\begingroup$ related, not sure if duplicate: mathematica.stackexchange.com/q/17250/9490 $\endgroup$ – Jason B. Mar 26 '18 at 13:44
  • $\begingroup$ Recalculating the figure using ParametricPlot is not an option, it is too much time consuming. $\endgroup$ – Guillermo Oliver Mar 26 '18 at 13:55

You have the output of your plot, and you want to modify the coordinates without replotting. You can do this easily when you realize the output from any Plot function will be a Graphics object that you can manipulate like any other expression.

For this case, we can use ReplaceAll to replace any coordinate pair of real numbers with a transformed version of it.

plot = RegionPlot[
   x^2 + y^3 < 2 && x + y < 1, {x, -2, 2}, {y, -2, 2}];
tfunc = TranslationTransform[{5, 5}];
plot2 = Show[
   plot /. pt : {x_Real, y_Real} :> tfunc@pt, 
   PlotRange -> {{3, 7}, {3, 7}}
{plot, plot2}

enter image description here

ReplaceAll is a blunt instrument, it replaces any occurrence of its pattern, so this could lead to unwanted side effects by replacing pairs of real numbers that don't represent a coordinate pair. But in most cases this works fine.

  • 2
    $\begingroup$ Since ParametricPlot[], RegionPlot[], and ilk produce a GraphicsComplex[] object, the safe way is to apply your transformations to that, e.g. Show[plot /. GraphicsComplex[pts_, rest__] :> GraphicsComplex[TranslationTransform[{5, 5}][pts], rest], PlotRange -> {{3, 7}, {3, 7}}] $\endgroup$ – J. M. is away Mar 26 '18 at 13:48
  • $\begingroup$ Thank you for this excellent solution! $\endgroup$ – Guillermo Oliver Mar 26 '18 at 13:54

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.